Menu

Reference / Http

inCidr()

function
function inCidr(string $ip, string $cidr): bool

Whether an IP address lies inside a CIDR network.

A bare address without a prefix is treated as /32 (IPv4) or /128 (IPv6). A malformed address or network gives false. An IPv4 address never matches an IPv6 network or the reverse, including the v4-mapped ::ffff:a.b.c.d form.

Parameters

$ip string
Address to test, IPv4 or IPv6 text form.
$cidr string
Network such as 10.0.0.0/8 or 2001:db8::/32.

Returns

bool — true when $ip is inside $cidr.

View source