欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

防CC攻击:在3秒内连续刷新页面5次以上将指向本机

程序员文章站 2022-05-08 19:15:52
...
php代码
<?php
session_start();
$nowtime = time() ;
if (session_is_registered('lasttime'))
{
 $lasttime = $_SESSION['lasttime'];
 $times = $_SESSION['times'] + 1;
 $_SESSION['times'] = $times;
}else{
 $lasttime = $nowtime;
 $times = 1;
 $_SESSION['times'] = $times;
 $_SESSION['lasttime'] = $lasttime;
}

if (($nowtime - $lasttime)=5){
  header(sprintf("Location: %s",'http://127.0.0.1'));
  exit;
 }
}else{
 $times = 0;
 $_SESSION['lasttime'] = $nowtime;
 $_SESSION['times'] = $times;
}

?>