$start_ip = "42.236.184.1";
$end_ip = "42.236.184.255";
$ip = "42.236.184.128";
check_ip($ip,$start_ip,$end_ip);
function check_ip($ip,$start_ip,$end_ip)
{
$ip = get_ip2long($ip);
$start_ip = get_ip2long($start_ip);
$end_ip = get_ip2long($end_ip);
if($ip >= $start_ip && $ip <= $end_ip)
{
return true;
}
return false;
}
// decbin() 十进制转二进制
// bindec() 二进制转十进制。函数将一个二进制数转换成 integer。可转换的最大的数为 31 位 1 或者说十进制的 2147483647。PHP 4.1.0 开始,该函数可以处理大数值,这种情况下,它会返回 float 类型。
function get_ip2long($ip)
{
return bindec(decbin(ip2long($ip)));
//方法二:return sprintf('%u',ip2long($ip)); //%u:不包含正负号的十进制数
}
更多PHP相关知识,请访问PHP中文网!