<?php
$whitelist = array('contact', 'about', 'user');
$_GET['page'] = array('contact');
$test = $_GET['page'];
if(isset($test))
{
if(in_array($whitelist, $test))
{
$got = $test;
echo $got;
}
else
{
$got = 'home';
echo $got;
}
}
?>
Now here, I should get the result as ‘contact’ but I’m getting ‘home’. Why is that ?
in_array first argument should be needle (meaning: what you are looking for) and second should be haystack (meaning: where we are looking for).
I think that you reversed those, as well as needl should be string (or other variable type), but not array.
So your script should look like this: