假如不欢迎匿名访客,在网站根目录index.php中设置蜜罐
<?php
header('Content-type: text/html; charset=utf-8');
$time = date('Y-m-d H:i:s',time());
$ip = $_SERVER["REMOTE_ADDR"];
$ua = $_SERVER["HTTP_USER_AGENT"];
$file = fopen("./noaccessin.txt", "a+"); //记录访问时间、ip、UA
fwrite( $file, "($time|$ip|$ua)\r\n");
$file = fopen("./miguan/miguanip.php", "a+"); //黑名单ip列表
$ban=file_get_contents("./miguan/miguanip.php"); //蜜罐
if(stripos($ban,$ip)) //防止重复记录
{
exit();
}
fwrite( $file, "$ip\r\n");
include("./miguan/miguan.php");
?>
miguan.php内容
<?php
//禁用ip地址
$ip=$_SERVER["REMOTE_ADDR"];
$ban=file_get_contents("./miguan/miguanip.php");
if(stripos($ban,$ip))
{
exit();
//die("Your IP Address is:$ip,you're forbiden to view this page!");
}
//echo "Your IP Address is:$ip,hello!";
?>
自己的主页可以放到文件夹下,注意处理路径,所有访问过蜜罐的ip都不能获取正常内容了。
include("./miguan/miguan.php");