How would I format the following code to check for multiple $userip results?
Such as IP’s:
173.33.202.122, 68.146.120.46
$userip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
if ($userip == "173.33.202.122"){
echo "You are blocked from using this.";
include "footer.php";
die;
}
I tried this below, but something is wrong here…other than me being new to PHP
if ($userip == “173.33.202.122” || “68.146.120.46”){
The only downside to a switch is if at a point you decide to change to a database driven IP blocker you would just append them as a case within it so an array would be the best option.
I would personally go with an array too, not to say that a switch doesnt have it’s uses though.
To answer the OP’s original question thought, you have to compare each value as you can ‘string together’ when comparing variables
if ($userip == "173.33.202.122" || $userip == "68.146.120.46"){