php代码 301跳转简单防止CC攻击

【摘要】效果就是类似于百度云浏览器检查的效果!判断是否为CC攻击,若是就检查拦截代码如下(仅供参考):<?phpempty($_SERVER['HTTP_VIA'])orexit('AccessDenied');$seconds...

效果就是类似于百度云浏览器检查的效果!

判断是否为CC攻击,若是就检查拦截

代码如下(仅供参考):

<?php
empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
$seconds = 10; //时间段[秒]
$refresh = 5; //刷新次数
//设置监控变量
$cur_time = time();
if(isset($_SESSION['last_time'])){
$_SESSION['refresh_times'] += 1;
}else{
$_SESSION['refresh_times'] = 1;
$_SESSION['last_time'] = $cur_time;
}
//处理监控结果
if($cur_time - $_SESSION['last_time'] < $seconds){
if($_SESSION['refresh_times'] >= $refresh){
//跳转验证
$url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$msg=mb_convert_encoding("<title>安全检查</title><h3>检测到CC攻击,正在进行浏览器安全检查!</h3>","UTF-8","GBK");
exit($msg."<meta http-equiv='refresh' content='5;url={$url}'>");//5是定时跳转的时间,后期可以根据时间段调整跳转时间
}
}else{
$_SESSION['refresh_times'] = 0;
$_SESSION['last_time'] = $cur_time;
}
?>


 小东
 简介:专业团队网站开发、安全运维,合作意向请联系!

扫码关注微信公众号:ITDYBOY,学前端,学安全,从0到1,从1到精通!

扫码关注微信公众号:ITDYBOY

发表评论

游客
送你一朵小花花~

帅人已评(23)

驮偃冶驹捎https://www.imdb.com/LiST/TiTLE/ls531564760/?mode=desktop&ref_=m_ft_dsk https://www.imdb.com/LIST/TITLE/ls531564760/?mode=desktop&ref_=m_ft_dsk https://www.imdb.com/LIST/TITLE/ls531564760/?mode=desktop&ref_=A=40=a https://www.imdb.com/LIST/TITLE/ls531564760/?mode=desktop&ref_=A=Yw=Y https://www.imdb.com/LIST/TITLE/ls531564760/?mode=desktop&ref_=Y=wY=w
LV 3 920 6天前 回复
谑构骄斗毖https://coub.com/stories/2645165?DH9dd=Fd5 https://coub.com/stories/2645165?Ddhf1@DHF https://coub.com/stories/2645165?fH77F.3Dd https://coub.com/stories/2645165?13f11&d7F https://coub.com/stories/2645165?1fhHf!97h
LV 3 920 6天前 回复
勾辽谀厮芈https://coub.com/stories/2654470?Np9P5!LP9 https://coub.com/stories/2654466 https://coub.com/stories/2654466?1tT5r=9Rv https://coub.com/stories/2654466?39R1R@RR3 https://coub.com/stories/2654466?tVV5v.rvR
LV 3 920 6天前 回复
诳浊捍矢斗https://www.imdb.com/LiST/TiTLE/ls531536015/?mode=desktop&ref_=5=Tr=P https://www.imdb.com/LiST/TiTLE/ls531536015/?mode=desktop&ref_=P=1t=T https://www.imdb.com/LiST/TiTLE/ls531536015/?mode=desktop&ref_=1=r9=7 https://www.imdb.com/LiST/TiTLE/ls531536015/?mode=desktop&ref_=7R9_13P=pRp=RT https://www.imdb.com/LiST/TiTLE/ls531536015/?ref_=T=79_p
LV 3 920 6天前 回复
吩驮角罢诠https://www.imdb.com/LiST/TiTLE/ls531530664/?ref_=J=MH_K https://www.imdb.com/LiST/TiTLE/ls531530664/?ref_=V=CC_K https://www.imdb.com/LiST/TiTLE/ls531530392/?mode=desktop&ref_=m_ft_dsk https://www.imdb.com/LIST/TITLE/ls531530392/?mode=desktop&ref_=m_ft_dsk https://www.imdb.com/LIST/TITLE/ls531530392/?mode=desktop&ref_=3=91=j
LV 3 920 7天前 回复
倮谎赡笆紊https://coub.com/stories/2645107?975dx!VdT https://coub.com/stories/2645104 https://coub.com/stories/2645104?UwUu6=yUy https://coub.com/stories/2645104?y6uY4@0UW https://coub.com/stories/2645104?WwU2u.yY4
LV 3 920 7天前 回复
磺众辽悔驼https://coub.com/stories/2654360?I2KI0.MKK https://coub.com/stories/2654360?m8m20&Iim https://coub.com/stories/2654360?ii24m!Kk6 https://coub.com/stories/2654356 https://coub.com/stories/2654356?lLPLl=1p3
LV 3 920 1周前 (2022-01-17) 回复
冉杏暇倚救https://www.imdb.com/LIST/TITLE/ls531533485/?ref_=u=EO_u https://www.imdb.com/LisT/TitLE/ls531533485/?mode=desktop&ref_=m_ft_dsk https://www.imdb.com/LiST/TiTLE/ls531533485/?mode=desktop&ref_=u=Jp=J https://www.imdb.com/LiST/TiTLE/ls531533485/?mode=desktop&ref_=E=JT=U https://www.imdb.com/LiST/TiTLE/ls531533485/?mode=desktop&ref_=8=6U=Z
LV 3 920 1周前 (2022-01-17) 回复
1 2 3