Test for IP in Array Always Fails on First IP

There are two pieces to this code: 1) Interpreting the list of allowed IPs from a textarea, delimited by newline character, and 2) Checking if a given user’s IP is in the allowed list of IPs.

Part 1) Parse list of IPs delimited by newline character, and trim whitespace:

$_POST['allowed_ips'] = "    67.6.134.102     
  97.118.69.236    ";

$ips = array_map('trim', explode("\n", $_POST['allowed_ips']));
var_dump($ips); //This should match your Array() output from above

Part 2) Check list of allowed IPs against the user’s current IP:

var_dump(in_array($_SERVER['REMOTE_ADDR'], $ips));

in_array() allows you to take a string and check if it exists as a value in an array. Since you have a list of all IPs you want to allow, you just need to check if the user’s current IP ($_SERVER['REMOTE_ADDR']) is in the array of allowed IPs.