php让某ip或ip地址段访问的方法:1、禁用单个ip,代码为【$ip=$_SERVER["REMOTE_ADDR"]】;2、禁用ip段,代码为【while($ip[count($ip-1)]!='.')$ip=substr($ip)】。

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