How does one achieve multiple checks against one value? I think I'm being a little bit stupid...
What I want to achieve is this:
if(basename($_SERVER['SCRIPT_NAME']) != ("1.php" || "2.php" || "3.php"){
header('Location: elsewhere.php');
}
rather than:
if(basename($_SERVER['SCRIPT_NAME']) != "1.php" && basename($_SERVER['SCRIPT_NAME']) != "2.php" && basename($_SERVER['SCRIPT_NAME']) != "3.php" && basename($_SERVER['SCRIPT_NAME']) != "4.php"){
header('Location: elsewhere.php');
}
I've written it out a few times but I'm clearly licking windows.
Thanks in advance!
you can write
$files = array("1.php", "2.php", "3.php", "4.php");//so on
if(!in_array(basename($_SERVER['SCRIPT_NAME']), $files)){
header('Location: elsewhere.php');
}
yes another method is (little bit faster than above one)
if(array_diff((array)(basename($_SERVER['SCRIPT_NAME'])),array("1.php", "2.php", "3.php", "4.php")))
{
header('Location: elsewhere.php');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With