Trying to understand || for if statement

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 :slight_smile:

if ($userip == “173.33.202.122” || “68.146.120.46”){

if ($userip == "173.33.202.122" || $userip == "68.146.120.46"){

An easier way to check against multiple IP’s is to use an array

$check_ip = array('173.33.202.122','68.146.120.46');

if (in_array($userip, $check_ip)) {
    // PHP code to run here
}

Id use a switch…

switch($userip){

      case '173.33.202.122' : /*do stuff*/; break;
      case '68.146.120.46' : /*do stuff*/; break;
}

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"){