Home >Backend Development >PHP Tutorial >PHP script to calculate whether they are in the same subnet_PHP tutorial
/*
For example: 192.16.1.13
and: 255.255.255.0
, and calculate, it is required to be 192.16.1.0
*/
$ip = "192.16.1.13";
echo get_net($ip,"255.255.255.0");
function get_net($ip,$hide="255.255.255.255") {
$a = explode(".",$ip);
$b = explode(".",$hide) ;
for($i=0;$i<4;$i++)
$r[$i] = (int)$a[$i] & (int)$b[$i];
return join(".",$r);
}
?>