Home >php教程 >PHP源码 >防CC攻击:在3秒内连续刷新页面5次以上将指向本机

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

PHP中文网
PHP中文网Original
2016-05-25 17:10:581158browse

php代码

<?php
session_start();
$nowtime = time() ;
if (session_is_registered(&#39;lasttime&#39;))
{
 $lasttime = $_SESSION[&#39;lasttime&#39;];
 $times = $_SESSION[&#39;times&#39;] + 1;
 $_SESSION[&#39;times&#39;] = $times;
}else{
 $lasttime = $nowtime;
 $times = 1;
 $_SESSION[&#39;times&#39;] = $times;
 $_SESSION[&#39;lasttime&#39;] = $lasttime;
}

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

?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn