溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何編寫簡易防CC攻擊刷新跳轉(zhuǎn)的代碼

發(fā)布時間:2021-10-12 10:17:39 來源:億速云 閱讀:130 作者:iii 欄目:編程語言

本篇內(nèi)容主要講解“如何編寫簡易防CC攻擊刷新跳轉(zhuǎn)的代碼”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“如何編寫簡易防CC攻擊刷新跳轉(zhuǎn)的代碼”吧!

自制簡易防CC攻擊刷新跳轉(zhuǎn)代碼,每秒刷新過多后跳轉(zhuǎn)防cc頁,5秒后反回網(wǎng)站首頁,感覺只能防一下亂刷新的人,就是打開網(wǎng)站一通亂點的人。

使用:以WordPress為例,在根目錄創(chuàng)建cc.php文件,把php代碼添加到里面保存,再創(chuàng)建cc.html文件把html代碼放入保存,在到根目錄的index.php文件最前面加上調(diào)用代碼,調(diào)用cc.php文件即可,可把cc.php里的時間修改周期改長點。

創(chuàng)建一個PHP文件名為cc.php復制以下代碼放進去:

<?php
//代理IP直接退出
emptyempty($_SERVER[''HTTP_VIA'']) or exit(''Access Denied'');
//防止快速刷新
session_start();
$seconds = ''3''; //時間段[秒]
$refresh = ''8''; //刷新次數(shù)
//設(shè)置監(jiān)控變量
$cur_time = time();
if(isset($_SESSION[''last_time''])){
 $_SESSION[''refresh_times''] += 1;
}else{
 $_SESSION[''refresh_times''] = 1;
 $_SESSION[''last_time''] = $cur_time;
}
//處理監(jiān)控結(jié)果
if($cur_time - $_SESSION[''last_time''] < $seconds){
 if($_SESSION[''refresh_times''] >= $refresh){
  //跳轉(zhuǎn)防cc頁
  header(sprintf(''Location:%s'', ''https://www.12580sky.com/cc.html''));
  exit(''Access Denied'');
 }
}else{
 $_SESSION[''refresh_times''] = 0;
 $_SESSION[''last_time''] = $cur_time;
}
?>

再創(chuàng)建一個cc.html文件復制以下代碼放進去:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>防CC刷新攻擊中,5秒后跳轉(zhuǎn)首頁</title>
<meta http-equiv="refresh" content="5;url=/" />
<style>*{box-sizing:inherit;}body{min-height:100vh;display:flex;justify-content:center;align-items:center;background:#151924;padding:0;margin:0;}.loading{--color:#F5F9FF;--duration:2000ms;font-family:Roboto,Arial;font-size:24px;position:relative;white-space:nowrap;user-select:none;color:var(--color);}.loading span{--x:0;--y:0;--move-y:0;--move-y-s:0;--delay:0ms;display:block;position:absolute;top:0;left:0;width:1px;text-indent:calc(var(--x) * -1);overflow:hidden;transform:translate(var(--x),var(--y));}.loading.start div{opacity:0;}.loading.start span{animation:move var(--duration) ease-in-out var(--delay);}@keyframes move{30%{transform:translate(var(--x),var(--move-y));}82%{transform:translate(var(--x),var(--move-y-s));}</style>
</head>
<body>
<div class="loading">防CC刷新攻擊中,5秒后跳轉(zhuǎn)首頁</div><br>
    <script src="https://cdn.bootcss.com/jquery/3.3.0/jquery.min.js"></script>
    <script type="text/javascript">
$(document).ready(function(){let loading=$(''.loading'').wrapInner(''<div></div>''),min=20,max=70,minMove=10,maxMove=20;startAnimation(loading);loading.on(''animationend webkitAnimationEnd oAnimationEnd'',''span:last-child'',e=>{startAnimation(loading)});function setCSSVars(elem,min,max,minMove,maxMove){let width=Math.ceil(elem.width()),text=elem.text();for(let i=1;i<width;i++){let num=Math.floor(Math.random()*(max-min+1))+min,numMove=Math.floor(Math.random()*(maxMove-minMove+1))+minMove,dir=(i%2==0)?1:-1,spanCurrent=elem.find(''span:eq(''+i+'')''),span=spanCurrent.length?spanCurrent:$(''<span />'');span.css({''--x'':i-1+''px'',''--move-y'':num*dir+''px'',''--move-y-s'':((i%2==0)?num*dir-numMove:num*dir+numMove)+''px'',''--delay'':i*10+''ms''});if(!spanCurrent.length){elem.append(span.text(text))}}}function startAnimation(elem){elem.removeClass(''start'');setCSSVars(elem,min,max,minMove,maxMove);void elem[0].offsetWidth;elem.addClass(''start'')}});
</script>
</body>
</html>

最后在首頁文件調(diào)用cc.php代碼:

require ''cc.php'';

到此,相信大家對“如何編寫簡易防CC攻擊刷新跳轉(zhuǎn)的代碼”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

php
AI