当前位置:首页>WordPress>WordPress教程>WordPress简单防止CC(5秒盾)PHP通用

WordPress简单防止CC(5秒盾)PHP通用

前言

利用检测cookie是否为正常的值,来确定是否为正常用户访问。PHP写的所以如果攻击的人代理很多的话,效果还是不大的!所以!做人要低调!

代码

建立一个cc.php文件

<?的PHP
定义('SYSTEM_ROOT' ,目录名(preg_replace ('@ \\(。* \\(。* $ @' ,'' ,preg_replace ('@ \\(。* \\(。* $ @' ,`` ,__FILE__ )))。'/' );    
session_start ();
date_default_timezone_set ('亚洲/上海' );
标头('Content-Type:text / html; charset = UTF-8' );
函数getspider ($ useragent = '' ){
如果(CC_Defender == 2 )返回false ; 
if (!$ useragent ){ $ useragent = $ _SERVER [ 'HTTP_USER_AGENT' ];}
$ useragent = strtolower ($ useragent );
if (strpos ($ useragent ,'baiduspider' )!== false ){ 返回'baiduspider' ;}     
if (strpos ($ useragent ,'googlebot' )!== false ){ 返回'googlebot' ;}     
if (strpos ($ useragent ,'soso' )!== false ){ 返回'soso' ;}     
if (strpos ($ useragent ,'bing' )!== false ){ 返回'bing' ;}     
if (strpos ($ useragent ,'yahoo' )!== false ){ 返回'yahoo' ;}     
if (strpos ($ useragent ,'sohu-search' )!== false ){ 返回'Sohubot' ;}     
if (strpos ($ useragent ,'sogou' )!== false ){ 返回'sogou' ;}     
if (strpos ($ useragent ,'youdaobot' )!== false ){ 返回'YoudaoBot' ;}     
if (strpos ($ useragent ,'yodaobot' )!== false ){ 返回'YodaoBot' ;}     
if (strpos ($ useragent ,'robozilla' )!== false ){ 返回'Robozilla' ;}     
if (strpos ($ useragent ,'msnbot' )!== false ){ 返回'msnbot' ;}     
if (strpos ($ useragent ,'lycos' )!== false ){ 返回'Lycos' ;}     
if (strpos ($ useragent ,'ia_archiver' )!== false || strpos ($ useragent ,'iaarchiver' )!== false ){ 返回'alexa' ;}         
if (strpos ($ useragent ,'archive.org_bot' )!== false ){ 返回'Archive' ;}      
if (strpos ($ useragent ,'robozilla' )!== false ){ 返回'Robozilla' ;}      
if (strpos ($ useragent ,'sitebot' )!== false ){ 返回'SiteBot' ;}      
if (strpos ($ useragent ,'mj12bot' )!== false ){ 返回'MJ12bot' ;}      
if (strpos ($ useragent ,'gosospider' )!== false ){ 返回'gosospider' ;}      
if (strpos ($ useragent ,'gigabot' )!== false ){ 返回'Gigabot' ;}      
if (strpos ($ useragent ,'yrspider' )!== false ){ 返回'YRSpider' ;}      
if (strpos ($ useragent ,'gigabot' )!== false ){ 返回'Gigabot' ;}      
if (strpos ($ useragent ,'jikespider' )!== false ){ 返回'jikespider' ;}      
if (strpos ($ useragent ,'addsugarspiderbot' )!== false ){ 返回'AddSugarSpiderBot' ; / *非常少* / }      
if (strpos ($ useragent ,'testspider' )!== false ){ 返回'TestSpider' ;}      
if (strpos ($ useragent ,'etaospider' )!== false ){ 返回'EtaoSpider' ;}      
if (strpos ($ useragent ,'wangidspider' )!== false ){ 返回'WangIDSpider' ;}      
if (strpos ($ useragent ,'foxspider' )!== false ){ 返回'FoxSpider' ;}      
if (strpos ($ useragent ,'docomo' )!== false ){ 返回'DoCoMo' ;}      
if (strpos ($ useragent ,'yandexbot' )!== false ){ 返回'YandexBot' ;}      
if (strpos ($ useragent ,'ezooms' )!== false ){ 返回'Ezooms' ; / *个人* / }      
if (strpos ($ useragent ,'sinaweibobot' )!== false ){ 返回'SinaWeiboBot' ;}      
if (strpos ($ useragent ,'catchbot' )!== false ){ 返回'CatchBot' ;}      
if (strpos ($ useragent ,'surveybot' )!== false ){ 返回'SurveyBot' ;}      
if (strpos ($ useragent ,'dotbot' )!== false ){ 返回'DotBot' ;}      
if (strpos ($ useragent ,'purebot' )!== false ){ 返回'Purebot' ;}      
if (strpos ($ useragent ,'ccbot' )!== false ){ 返回'CCBot' ;}      
if (strpos ($ useragent ,'mlbot' )!== false ){ 返回'MLBot' ;}      
if (strpos ($ useragent ,'adsbot-google' )!== false ){ 返回'AdsBot-Google' ;}     
if (strpos ($ useragent ,'ahrefsbot' )!== false ){ 返回'AhrefsBot' ;}     
if (strpos ($ useragent ,'spbot' )!== false ){ 返回'spbot' ;}     
if (strpos ($ useragent ,'augustbot' )!== false ){ 返回'AugustBot' ;}     
返回false ; 
}
 
if ($ _GET [ 'rand' ] && $ _SESSION [ 'rand_session' ]!= $ _GET [ 'rand' ]){ 
@header ('Content-Type:text / html; charset = UTF-8' );
exit ('<b>浏览器不支持COOKIE或不正常访问!</ b>' );
}
if (!$ _SESSION [ 'rand_session' ] && $ nosecu != true ){ 
如果(!getspider ()){
$ rand_session = MD5 (uniqid 。()蘭特(1 ,1000 ));
$ _SESSION [ 'rand_session' ] = $ rand_session ;
退出(“ <!DOCTYPE HTML>
<html>
<头>
<meta charset = \“ UTF-8 \” />
<meta name = \“ viewport \” content = \“ width = device-width,initial-scale = 1,maximum-scale = 1 \” />
 
<title>安全检查中... </ title>
 <script> var i = 5; 
  var intervalid; 
  intervalid = setInterval(\“ fun()\”,1000); 
函数fun(){ 
如果(i == 0){ 
window.location.href = \“?{$ _ SERVER ['QUERY_STRING']}&rand = {$ rand_session} \”; 
clearInterval(intervalid); 
} 
document.getElementById(\“ mes \”)。innerHTML = i; 
一世 - ; 
} 
</ script> 
<样式>
html,正文{width:100%; 高度:100%; 边距:0; 填充:0;}
    正文{background-color:#ffffff; 字体家族:Helvetica,Arial,無襯線;字体大小:100%;}
    h1 {font-size:1.5em; 顏色:#404040; 文字對齊:居中;}
    p {font-size:1em; 顏色:#404040; 文字對齊:居中;邊距:10px 0 0 0;}
    #spinner {保证金:0自动30px自动;显示:阻止;}
    .attribution {margin-top:20px;}
  </ style>
  </ head>
<身体>
  <table width = \“ 100%\” height = \“ 100%\” cellpadding = \“ 20 \”>
    <tr>
      <td align = \“ center \” valign = \“ middle \”>
    <noscript> <h2>請打開瀏覽器的javascript,然後刷新瀏覽器</ h2> </ noscript>
  <h1> <span data-translate = \“ checking_browser \”>瀏覽器安全檢查中... </ span> </ h1>
    <p data-translate = \“ process_is_automatic \”> </ p>
    <p data-translate = \“ allow_5_secs \”>還剩<span id = \“ mes \”> 5 </ span>秒</ p>
  </ div>
</ div>
  </ td>
    </ tr>
</ table> </ body> </ html>“ );
}
}

调用:

WordPress調用,主題/header.php第一行添加代碼:

<?php get_template_part ('template / cc' ); ?>   

 

首次访问网站检测浏览器cookie通過才能正常的访問您的网站,搜索引擎蜘蛛已经过滤,不影响收录,还有未加上的可以自己补充。平时没攻击的时候建议不要开启,会影响网站的体验,配合Nginx lua waf简单防御CC 攻击效果更佳。

©版权声明

本站资源大多来自网络,如有侵犯你的权益请联系管理员Ciyol 或给邮箱发送邮件 admin@ciyol.cn 我们会第一时间进行审核删除。站内资源为网友个人学习或测试研究使用,未经原版权作者许可,禁止用于任何商业途径!请在下载24小时内删除!


如果遇到评论下载的文章,评论后刷新页面点击对应的蓝字按钮即可跳转到下载页面本站资源少部分采用7z压缩,为防止有人压缩软件不支持7z格式,7z解压,建议下载7-zip(点击下载),zip、rar解压,建议下载WinRAR(点击下载)

给TA打赏
共{{data.count}}人
人已打赏
0 条回复A文章作者M管理员
    暂无讨论,说说你的看法吧
购物车
优惠劵
今日签到
有新私信 私信列表
搜索