求一个PHP的IP地址段限制程序。。。。

2025-03-22 09:48:28
推荐回答(1个)
回答1:

/*
检查IP
$outip : 当前查询的IP
$iplist : 拒绝的ip列表,多个用,隔开
如果查询的IP是拒绝IP列表中的,则函数返回false,反之返回true
*/
function outip($outip,$listip){

if (strpos($listip,$outip) === false) {
$arr = explode('.',$outip);
if (count($arr) <> 4) return false;
//是否是IP段
if (strpos($listip,$arr[0] . '.' . $arr[1] . '.' . $arr[2] . '.*') === false) {
return false;
} else {
return true;
}
} else {
return true;
}
}