判斷IP是否在某個網段內
public function ip_in_network($ip, $network)
{
$ip = (double) (sprintf("%u", ip2long($ip)));
$s = explode('/', $network);
$network_start = (double) (sprintf("%u", ip2long($s[0])));
$network_len = pow(2, 32 - $s[1]);
$network_end = $network_start + $network_len - 1;
if ($ip >= $network_start && $ip <= $network_end)
{
return true;//本機ip屬於這個網段返回true
}
return false;//本機ip屬於這個網段返回false
}