= $lower_dec) && ($ip_dec <= $upper_dec)); } return false; } } public static function IsIpInCidrRange(string $ip, string $cidr) { list($subnet, $bits) = explode('/', $cidr); if ($bits === null) { $bits = 32; } $ip = ip2long($ip); $subnet = ip2long($subnet); $mask = -1 << (32 - $bits); $subnet &= $mask; # nb: in case the supplied subnet wasn't correctly aligned return ($ip & $mask) == $subnet; } } }