php禁止ip访问的方法:首先创建一个PHP示例文件;然后通过“if(stripos($ban,$ip)){die("Your IP Address is:$ip,you're forbiden to...")}”方法禁止ip访问即可。

推荐:《PHP视频教程》
php禁止某ip或ip地址段访问的方法
<?php include("banIP.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!";
?>ban.dat文件如下:
BEGIN: 119.184.251.245 127.0.0.1 192.168.1.100
禁用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!";
?>以上就是php 如何禁止ip访问的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号