$ip_start = get_iplong('192.168.1.1 

'); //起始ip  
$ip_end = get_iplong('192.168.1.255 

');//至ip  
$ip = get_iplong('192.168.1.127 

');//判断的ip  
//可以这样简单判断  
if($ip>=$ip_start && $ip <=$ip_end){  
    echo 'IP在此范围内';  
}else{  
    echo 'IP不在此范围';  
}  
/** 
 * 将ip地址转换成int型 
 * @param $ip  ip地址 
 * @return number 返回数值 
 */  
function get_iplong($ip){  
    //bindec(decbin(ip2long('这里填ip地址')));  
    //ip2long();的意思是将IP地址转换成整型 ,  
    //之所以要decbin和bindec一下是为了防止IP数值过大int型存储不了出现负数。  
    return bindec(decbin(ip2long($ip)));  
}  
posted on 2017-08-04 10:49  Akoasm码农  阅读(1325)  评论(0编辑  收藏  举报