php禁止某ip或ip地址段訪問的方法(轉載)

<?php include("banIP.php");?>php

禁用單個ip以下:
<?php
//禁用ip地址
$ip=$_SERVER["REMOTE_ADDR"];
$ban=file_get_contents("ban.dat");
if(stripos($ban,$ip))
{
die("Your IP Address is:$ip,you're forbiden to view this page!");
}
echo "Your IP Address is:$ip,hello!";
?>ide

ban.dat文件以下:
BEGIN:
119.184.251.245
127.0.0.1
192.168.1.100this

禁用ip段以下:
<?php
//禁用ip地址
$ip=$_SERVER["REMOTE_ADDR"];
while($ip[count($ip-1)]!='.')$ip=substr($ip,1, -1); //整理出ip段
$ban=file_get_contents("ban.dat");
if(stripos($ban,$ip))
{
die("U're forbiden to view this page!");
}
echo "Hello!";
?>
---------------------
做者:luckymaoyy
來源:CSDN
原文:https://blog.csdn.net/luckymaoyy/article/details/73733396
版權聲明:本文爲博主原創文章,轉載請附上博文連接!.net

相關文章
相關標籤/搜索