You are here

function maintenance_exempt_ipCIDRCheck in Maintenance Exempt 7

Helper function to check against CIDR.

Thanks claudiu - http://www.php.net/manual/en/ref.network.php#74656

1 call to maintenance_exempt_ipCIDRCheck()
maintenance_exempt_by_cidr_notation in ./maintenance_exempt.module
Helper function to go through array looking in an attempt to match netmask.

File

./maintenance_exempt.module, line 177
Allow exemption of maintenance mode based on either certain set IP addresses or matching a set query string value.

Code

function maintenance_exempt_ipCIDRCheck($IP, $CIDR) {
  list($net, $mask) = explode("/", $CIDR);
  $ip_net = ip2long($net);
  $ip_mask = ~((1 << 32 - $mask) - 1);
  $ip_ip = ip2long($IP);
  $ip_ip_net = $ip_ip & $ip_mask;
  return $ip_ip_net == $ip_net;
}