function maintenance_exempt_ip_cidr_check in Maintenance Exempt 8
Helper function to check against CIDR.
Thanks claudiu - http://www.php.net/manual/en/ref.network.php#74656
Parameters
string $ip: The IP address to check.
string $cidr: The netmask in CIDR notation.
Return value
bool TRUE if the IP address matches.
1 call to maintenance_exempt_ip_cidr_check()
- maintenance_exempt_by_cidr_notation in ./
maintenance_exempt.module - Check if an IP address using CIDR notation should be exempt.
File
- ./
maintenance_exempt.module, line 158 - Allow exemption from maintenance mode.
Code
function maintenance_exempt_ip_cidr_check($ip, $cidr) {
[
$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;
}