Control modules by IP address

E-mail
(2 votes, average 2.50 out of 5)

In company intranet systems you may be able to identify certain groups of users by the IP address of the client. These MetaMod recipes allow you to to detect an individual or range of IP addresses, and change modules based on this information.

Single IP address check

if ($_SERVER['REMOTE_ADDR'] == "123.22.33.44") return 56;

IP address range example 123.22.33.50-55

// split ip address into numbers, we test individually
$ip_numbers = explode(".",$_SERVER['REMOTE_ADDR']);
if ($ip_numbers[0] == 123 &&
 $ip_numbers[1] == 22 &&
 $ip_numbers[2] == 33 &&
 $ip_numbers[3] >= 50 &&
 $ip_numbers[3] <= 55) return 12;