Home > php教程 > PHP源码 > body text

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

PHP中文网
Release: 2016-05-25 17:10:58
Original
1121 people have browsed it

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;
}

?>
Copy after login

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!