+ -
当前位置:首页 → 问答吧 → 关于限制IP访问的代码和问题

关于限制IP访问的代码和问题

时间:2011-05-12

来源:互联网

<!--code.start-->?
if(!strstr($_SERVER['REMOTE_ADDR'],'122.194.75.12'))
{
echo"此IP不允许进入";
exit();
}
?<!--code.end-->


加上这样的代码 即允许该ip可以访问

如果需要122.194.75.1-122.194.75.255所有ip访问又该如何实现呢?

试了'122.194.75.*'无效的。。

请教各位有何解决办法

作者: qiudan   发布时间: 2011-05-12

function ip2lng($ip){
return bindec(decbin(ip2long($ip))); #这里可以先判断下ip格式再转换.不写了
}

if(ip2lng($_SERVER['REMOTE_ADDR'])>ip2lng('122.194.75.1') && $_SERVER['REMOTE_ADDR'])<ip2lng('122.194.75.255')){
echo"此IP不允许进入";
exit();
}

作者: shirne   发布时间: 2011-05-12