php讓某ip或ip地址段訪問的方法:1、禁用單個(gè)ip,代碼為【$ip=$_server["remote_addr"]】;2、禁用ip段,代碼為【while($ip[count($ip-1)]!='.')$ip=substr($ip)】。
【相關(guān)學(xué)習(xí)推薦:php圖文教程】
php讓某ip或ip地址段訪問的方法:
使用時(shí)只需:
<?php include("banip.php");?>即可
禁用單個(gè)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!"; ?>相關(guān)學(xué)習(xí)推薦:php編程(視頻)