Using pear Net_IPv4 module one can find if a given IP address is in provided Network range or on the subnet.
<?php // check if IP falls in provided subnet include("Net/IPv4.php"); $ipAddr = "192.168.1.8"; $netAddr = "192.168.1.0/29"; // 192.168.1.0 - 192.168.1.7 $objIP = new Net_IPv4(); echo $objIP->ipInNetwork($ipAddr, $netAddr) ? "$ipAddr is in $netAddrn" : "$ipAddr is not in $netAddrn"; ?>
This requires pear Net_IPv4 module which can be installing in one of the following ways.
pear install Net_IPv4 php pyrus.phar install pear/Net_IPv4