编辑代码

<?php 
//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 

$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: ".$ip; 
    echo "</br>";
    echo "ip_start: ".$ip_start; 
    echo "</br>";
    echo "ip_end: ".$ip_end; 
    echo "</br>";
    echo 'IP在此范围内';
}else{
    echo "ip: ".$ip; 
    echo "</br>";
    echo "ip_start: ".$ip_start; 
    echo "</br>";
    echo "ip_end: ".$ip_end; 
    echo "</br>";
    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)));
}