Solution: in_array ip address explode not working

Author: Zeeshan Arshad     1519     07/23/2013

Estimated reading time: 0 minutes, 16 seconds

Problem: You are trying to match an IP address against multiple IP addresses using explode() but it's not working.

Solution:

$ip_addresses = '192.168.100.55, 192.168.100.5, 127.0.0.1';

// Allowed
if (in_array($_SERVER['REMOTE_ADDR'], array_map("trim", explode(',', $ip_addresses)))) {

echo 'ip address was found in array';

// Blocked
} else {

echo 'ip address was not found in array';

}


Was this topic helpful?

Yes
No
Subscribe YouTube Channel

Zeeshan Arshad is a self-taught and multi-dimensional person with extraordinary track record of success with international clients and students.

Feel free to contact him for your project, training purpose or guidance.