public static function isIpInCidr(string $ip, string $cidr): bool
    {
        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            throw new \UnexpectedValueException(
                "invalid value for ip; expecting an IPv4 address"
            );
        }

        list($range, $netmask) = static::parseCidr($cidr);
        $netmask = ~((1 << (32 - $netmask)) - 1);
        return ((ip2long($ip) & $netmask) === ip2long($range));
    }
public static function isIpInCidr(string $ip, string $cidr): bool
    {
        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            throw new \UnexpectedValueException(
                "invalid value for ip; expecting an IPv4 address"
            );
        }

        list($range, $netmask) = static::parseCidr($cidr);
        $netmask = ~((1 << (32 - $netmask)) - 1);
        return ((ip2long($ip) & $netmask) === ip2long($range));
    }
public static function isIpInCidr ( string $ ip , string $ cidr ) : bool { if ( ! filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { throw new \ UnexpectedValueException ( "invalid value for ip; expecting an IPv4 address" ) ; } list ( $ range , $ netmask ) = static :: parseCidr ( $ cidr ) ; $ netmask = ~ ( ( 1 << ( 32 - $ netmask ) ) - 1 ) ; return ( ( ip2long ( $ ip ) & $ netmask ) === ip2long ( $ range ) ) ; }
Determine whether an ip address is within a given CIDR

@param string $ip The ip to test
@param string $cidr The range to evaluate
@return bool
Determine whether an ip address is within a given CIDR