禁令IP范围PHP
我找到了此代码:
<?php
$ban_ip_range = array('10.49.*.*');
$user_ip = $_SERVER['REMOTE_ADDR'];
if(!empty($ban_ip_range)) {
foreach($ban_ip_range as $range) {
$range = str_replace('*','(.*)', $range);
if(preg_match('/'.$range.'/', $user_ip)) {
echo "NO access";
}
else {
echo 'you have access';
}
}
}
?>
此代码完全有效并且有效,问题是我想添加多个范围,所以我做到了:
$ban_ip_range = array('10.49.*.*','10.65.*.*');
但是,这个代码不起作用,它贯穿了条件的两个部分,它显示了:
"NO accessyou have access"
有什么方法可以解决吗?
I found this code:
<?php
$ban_ip_range = array('10.49.*.*');
$user_ip = $_SERVER['REMOTE_ADDR'];
if(!empty($ban_ip_range)) {
foreach($ban_ip_range as $range) {
$range = str_replace('*','(.*)', $range);
if(preg_match('/'.$range.'/', $user_ip)) {
echo "NO access";
}
else {
echo 'you have access';
}
}
}
?>
This code is completely functional and working, the thing is that I want to add more than one range so I did this:
$ban_ip_range = array('10.49.*.*','10.65.*.*');
But this one didn't work , it goes throught the two parts of the conditional and it shows :
"NO accessyou have access"
Any way of fixxing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用标志,找到匹配时切换它,在循环后对其进行评估。
Use a flag, toggle it when you find a match, evaluate it after the loop.