php代码|记录一个ip60秒访问次数(php记录访问次数及ip)

时间:2023-06-09 16:48:59   阅读:192
<?php
// 创建zshao-1.txt文件
$file = fopen("zshao-1.txt", "a+");
fclose($file);
// 记录来访ip和时间
$ip = $_SERVER['REMOTE_ADDR'];
$time = date('Y-m-d H:i:s');
$file = fopen("zshao-1.txt", "a+");
fwrite($file, $ip . ' ' . $time . "\n");
fclose($file);
// 检测当前来访的ip一分钟内访问了多少次
$file = fopen("zshao-1.txt", "r");
$count = 0;
while (!feof($file)) {
    $line = fgets($file);
    if (strpos($line, $ip) !== false && strtotime($time) - strtotime(substr($line, strpos($line, ' ') + 1)) <= 60) {
        $count++;
    }
}
fclose($file);
echo "当前IP一分钟内访问了" . $count . "次";
?>


php代码|记录一个ip60秒访问次数(php记录访问次数及ip)

上一篇:王者荣耀透视官网-王者荣耀透视(王者荣耀透视辅助工具)

下一篇:王者荣耀挂购买平台-王者荣耀:玩家花150元买青铜号,十分钟后转手卖了2000

网友评论