網站被惡意鏡像怎麼辦 php一段代碼輕鬆搞定(全面版)

有時候你會發現,你在搜索引擎輸入網站名稱的時候,出來的網站信息是大家的,可是域名倒是一個陌生的,這種狀況能夠基本肯定網站被鏡像了,那麼究竟什麼叫網站被鏡像?javascript

惡意鏡像,也叫惡意克隆,惡意解析,是指有人經過域名 A 記錄直接解析別人 IP 地址,從而獲得一個在訪問者眼中徹底相同網站的過程。其工做原理基本上是這樣子的:有用戶訪問鏡像站點時,程序就會來正版的站點查詢數據,並修改相關連接而後呈獻給用戶,實質上仍是在讀取原站的數據。嚴謹一點的解釋:經過複製整個網站或部分網頁內容並分配以不一樣域名和服務器,以此欺騙搜索引擎對同一站點或同一頁面進行屢次索引的行爲 。php

網站被鏡像的危害css

通俗的講,惡意鏡像者意圖利用本身有必定權重的域名進行威壓,經過某些手段複製了你的站點,除了域名不同以外,其餘內容如出一轍,用戶或許根本沒法分辨。甚至對於一些新的站點,搜索引擎都會迷惑到底哪一個是真的站點,那麼就有可能正牌的網站被刪除收錄,而盜版的卻被搜索引擎青睞。html

雖然目前咱們還不知道惡意鏡像咱們的網站到底有什麼意圖,但確定對咱們沒什麼好處,若是他這個域名有點什麼不健康的信息,那麼咱們被鏡像的站點有可能被污染掉,因此仍是要警戒這個現象。vue

如何知道本身的網站是否被鏡像java

複製本身網站的完整標題(PS:查看本身站點首頁源碼,其中 <title>龍笑天下 - 分享悲傷;共享快樂</title>),而後在谷歌和百度等搜索引擎裏搜索,如搜索:intitle 龍笑天下 - 分享悲傷;共享快樂,若是有其餘網站的網站標題、描述及網站內容跟你的同樣,只有域名不同,那就是被鏡像了。node

如何處理網站被鏡像laravel

這類鏡像看似一個完整的站點,其實上是每次用戶訪問鏡像站點,程序就會來正版的站點查詢數據,並修改相關連接而後呈獻給用戶。實質上仍是在讀取原站的數據。如下龍笑天下就列舉幾種解決方法,你們自行取捨使用!web

方法 1:查清鏡像網站的主機 Ip,經過禁止 Ip 來解決面試

本教程基於 WordPress 程序,其餘系統請自測!

一、獲取鏡像服務器 ip。注:這個 IP 可能不是 ping 到他域名的 IP

複製以下代碼,新建一個 php 文件,並命名爲「ip.php」上傳到你的網站根目錄。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
$file = "ip.txt" ; //保存的文件名
$ip = $_SERVER [ 'REMOTE_ADDR' ];
$handle = fopen ( $file , 'a' );
fwrite( $handle , "IP Address:" );
fwrite( $handle , "$ip" );
fwrite( $handle , "\n" );
fclose( $handele );
?>
 
<?php
$file = "ip.txt" ; //保存的文件名
$ip = $_SERVER [ 'REMOTE_ADDR' ];
$handle = fopen ( $file , 'a' );
fwrite( $handle , "IP Address:" );
fwrite( $handle , "$ip" );
fwrite( $handle , "\n" );
fclose( $handele );
?>

二、而後訪問你網站的鏡像站點,在地址後面加.../ip.php,而後你就會在網站根目錄找到 ip.txt 文件了,打開復制裏面的 ip 地址。

三、而後打開你的.htaccess 文件,在後面加上以下代碼(自行修改成剛剛得到的 ip)

?
1
2
3
4
5
6
7
#添加IP黑名單
Order Deny,Allow
Deny from 162.158.72.179
 
#添加IP黑名單
Order Deny,Allow
Deny from 162.158.72.179

固然,若是你使用 CDN,能夠直接在 CDN 後臺添加 ip 黑名單

這個時候你再刷新一下鏡像站點,是否是已經 403 報錯了呢?這個時候已經解決了這個鏡像站點,而後就等待蜘蛛將其解決掉吧。

此方法的缺點就是若是鏡像網站更換了 ip,那咱們的屏蔽就失敗了

方法 2:JS 來防禦

在頭部標籤:取自 @boke112 導航

<head></head>

<head></head>

里加上下面的 JS 代碼:

?
1
2
3
4
5
6
7
8
9
10
11
<script type= "text/javascript" >
if (document.location.host != "www.ilxtx.com" ) {
location.href = location.href.replace(document.location.host, 'www.ilxtx.com' );
}
</script>
 
<script type= "text/javascript" >
if (document.location.host != "www.ilxtx.com" ) {
location.href = location.href.replace(document.location.host, 'www.ilxtx.com' );
}
</script>

或加上如下的 JS 代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
<script type= "text/javascript" >
rthost = window.location.host;
if (rthost != "www.ilxtx.com" ) {
top.location.href = "https://www.ilxtx.com" ;
}
</script>
 
<script type= "text/javascript" >
rthost = window.location.host;
if (rthost != "www.ilxtx.com" ) {
top.location.href = "https://www.ilxtx.com" ;
}
</script>

注意:將上面代碼中的www.ilxtx.com改成你網站的首頁主地址,若是我上面填寫的不是我網站的主地址 www.ilxtx.com,而是 ilxtx.com 的話,就會致使網站一直刷新!

注:通過本站測試,若是鏡像站屏蔽了 JS,則該方法失效。因此,最好把方法 2 和方法 3 結合使用!

方法 3:Js 被屏蔽後防止鏡像的方法

將如下代碼加到網站的 header.php 中:代碼取自 @boke112

?
1
2
3
4
5
6
7
8
9
<div style= "display:none;" >
<script>proxy2016 = false;</script>
<img src= "" onerror= 'setTimeout(function(){if(typeof(proxy2016)=="undefined"){window.location.host="www.ilxtx.com";}},3000);' >
</div>
 
<div style= "display:none;" >
<script>proxy2016 = false;</script>
<img src= "" onerror= 'setTimeout(function(){if(typeof(proxy2016)=="undefined"){window.location.host="www.ilxtx.com";}},3000);' >
</div>

有些網站會屏蔽掉 JS 代碼(以下面的代碼) :

?
1
2
<script>...</script>
<script>...</script>

因此 <script>proxy2016 = false;</script> 代碼將被過濾掉,img 的 onerror 設置超時時間 3000 毫秒,將運行函數部分,檢測是否還存在 proxy2016 字符,若是沒有找到就會將主機的 URL 改成 www.ilxtx.com;爲了安全起見,將 js 部分可使用 js 代碼混淆(本站「JS 代碼混淆」 工具 或 站長之家 JS 混淆工具)。
本站的混淆結果以下:

?
1
2
3
4
5
6
7
8
9
<div style= "display:none;" >
<script>proxy2016 = false;</script>
<img src= " " onerror= 'setTimeout(function(){if(typeof(proxy2016)=="undefined"){window["\x6c\x6f\x63\x61\x74\x69\x6f\x6e"]["\x68\x6f\x73\x74"]="\x77\x77\x77\x2e\x69\x6c\x78\x74\x78\x2e\x63\x6f\x6d";}},3000);' >
</div>
 
<div style= "display:none;" >
<script>proxy2016 = false;</script>
<img src= " " onerror= 'setTimeout(function(){if(typeof(proxy2016)=="undefined"){window["\x6c\x6f\x63\x61\x74\x69\x6f\x6e"]["\x68\x6f\x73\x74"]="\x77\x77\x77\x2e\x69\x6c\x78\x74\x78\x2e\x63\x6f\x6d";}},3000);' >
</div>

通過個人測試,此代碼在 Chrome、IE11 和 360 極速瀏覽器上均有效,會跳轉到源站的原文章頁!在 Firefox 上則無效果,鏡像的文章頁並不會跳轉到原站...... 將代碼中 img 標籤的 src 引用地址改成空格或無效的圖片地址後,在 Firefox 上也起做用了!

方法 4:藉助 Img 的 Onerror 事件

20161119 更新(增長搜狗快照支持):此方法使用了後,會致使百度快照、谷歌快照、必應快照和搜狗快照等跳到 404 頁面(360 搜索快照則不會~),奈何不知怎麼弄,2016-11-10 再次通過張戈的指導,將原代碼中的:if( str1!=str3 ) 改成 :if( str1!=str3 && str3!="cache.baiducontent.com" && str3!="webcache.googleusercontent.com" && str3!="c.360webcache.com" && str3!="cncc.bingj.com" && str3!="snapshot.sogoucdn.com" ) 。估計要等快照更新時才能知道效果了!

20161127:通過驗證,上述更新已經起做用了!具體效果,請點我~

20171022 更新:從張戈那看到,這段代碼會由於 onerror 死循環形成瀏覽網頁的電腦高負載(CPU 飆升),所以在代碼 onerror 觸發事件中加入 onerror 清空機制,即加入this.onerror=null。【博客網頁致使電腦 CPU 飆升的問題解決記錄】

經過拆分域名連接與鏡像站比對,而後用 img 標籤 src 空值觸發 onerror 來執行 js 比對,比對失敗則跳轉回源站。

①、WordPress 專用版

通過 @張戈 童學的不斷改進(IE 不支持 window.stop() 函數,因此「20160909 版本」失效...),已經完美的適配 Firefox、Chrome、IE11 和 360 極速瀏覽器,並且能夠跳轉至源站的相應文章頁,在此衷表感謝!下面 3 段任選一個便可。效果請看這裏:http://www.ilxtx.com.3s3s.org/the-shawshank-redemption-1994.html

代碼以下:(複製粘貼到主題的 functions.php 最後一個?>以前)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* 網站被惡意鏡像怎麼辦 一段代碼輕鬆搞定(全面版) - 龍笑天下
* 最後更新時間:20171022  發佈時間:20160912
* 出自:zhangge.net
*/
add_action( 'wp_footer' , 'lxtx_deny_mirrored_websites' );
function lxtx_deny_mirrored_websites(){
   $currentDomain = 'www" + ".ilxtx." + "com' ;
   // $currentDomain = '"zhangge." + "net"';
   echo '<img style="display:none" src=" " onerror=\'this.onerror=null;var str1="' . $currentDomain . '";str2="docu"+"ment.loca"+"tion.host";str3=eval(str2);if( str1!=str3 && str3!="cache.baiducontent.com" && str3!="webcache.googleusercontent.com" && str3!="c.360webcache.com" && str3!="cncc.bingj.com" && str3!="snapshot.sogoucdn.com" ){ do_action = "loca" + "tion." + "href = loca" + "tion.href" + ".rep" + "lace(docu" +"ment"+".loca"+"tion.ho"+"st," + "\"' . $currentDomain . '\"" + ")";eval(do_action) }\' />' ;
}
 
/**
* 網站被惡意鏡像怎麼辦 一段代碼輕鬆搞定(全面版) - 龍笑天下
* 最後更新時間:20171022  發佈時間:20160912
* 出自:zhangge.net
*/
add_action( 'wp_footer' , 'lxtx_deny_mirrored_websites' );
function lxtx_deny_mirrored_websites(){
   $currentDomain = 'www" + ".ilxtx." + "com' ;
   // $currentDomain = '"zhangge." + "net"';
   echo '<img style="display:none" src=" " onerror=\'this.onerror=null;var str1="' . $currentDomain . '";str2="docu"+"ment.loca"+"tion.host";str3=eval(str2);if( str1!=str3 && str3!="cache.baiducontent.com" && str3!="webcache.googleusercontent.com" && str3!="c.360webcache.com" && str3!="cncc.bingj.com" && str3!="snapshot.sogoucdn.com" ){ do_action = "loca" + "tion." + "href = loca" + "tion.href" + ".rep" + "lace(docu" +"ment"+".loca"+"tion.ho"+"st," + "\"' . $currentDomain . '\"" + ")";eval(do_action) }\' />' ;
}

Ps:若是是丟到 wp_head,通過測試發現圖片放到 head,瀏覽器會自動進行錯誤調整,致使一些原本在 head 的元素被丟到了 body 當中,好比 style.css,估計網頁標準中 head 裏面就不該該放置圖片,因此移到了 footer 當中。

?
1
2
3
4
5
6
7
8
9
10
11
/**
* 網站被惡意鏡像怎麼辦 一段代碼輕鬆搞定(全面版) - 龍笑天下
* 出自:zhangge.net
*/
add_action( 'wp_footer' , 'lxtx_deny_mirrored_websites' );
function lxtx_deny_mirrored_websites(){
  $currentDomain = "www' + '.ilxtx.' + 'com" ;
  // $currentDomain = "zhangge' + '.' + 'net";
  echo '<img style="display:none" src="nothing" onerror="this.onerror=null;var str1=\'' . $currentDomain . '\';str2=\'docu\'+\'ment.loca\'+\'tion.host\';str3=eval(str2);if( str1!=str3 ){ do_action = \'loca\' + \'tion.\' + \'href = loca\' + \'tion.href\' + \'.rep\' + \'lace(docu\' +\'ment\'+\'.loca\'+\'tion.ho\'+\'st,\' + \'\\\'' . $currentDomain . '\\\'\' + \')\';eval(do_action) }" />' ;
}
?
1
2
3
4
5
6
7
8
9
10
/**
* 網站被惡意鏡像怎麼辦 一段代碼輕鬆搞定(全面版) - 龍笑天下
* zhangge.net修改
*/
add_action( 'wp_footer' , 'lxtx_kimsom_reverse_proxy_defense' , 99);
function lxtx_kimsom_reverse_proxy_defense(){
  $currentDomain = '"www." + "ilxtx" + ".com"' ;
  echo '<img style="display:none" id="inlojv-rpd" src="nothing" data-url="' .home_url(). '" onerror=\'this.onerror=null;var str0=document.getElementById("inlojv-rpd").attributes.getNamedItem("data-url").nodeValue;var ishttps="https:"==document.location.protocol?true:false;if(ishttps){var str1="https"+"://";}else{var str1="http"+"://";}var str2=' . $currentDomain . ';var str3=str1+str2;if( str0!=str3 ){location.href = location.href.replace(document.location.host,' . $currentDomain . ');}\'/>' ;
}

Tips:若是想像「20160909 版本」同樣有個提示語,可將上面這段代碼改成此

?
1
2
3
4
5
add_action( 'wp_footer' , 'lxtx_kimsom_reverse_proxy_defense' , 99);
function lxtx_kimsom_reverse_proxy_defense(){
  $currentDomain = '"www." + "ilxtx" + ".com"' ;
  echo '<img style="display:none" id="inlojv-rpd" src="nothing" data-url="' .home_url(). '" onerror=\'this.onerror=null;var str0=document.getElementById("inlojv-rpd").attributes.getNamedItem("data-url").nodeValue;var ishttps="https:"==document.location.protocol?true:false;if(ishttps){var str1="https"+"://";}else{var str1="http"+"://";}var str2=' . $currentDomain . ';var str3=str1+str2;if( str0!=str3 ){alert("\u8b66\u544a\uff01\u68c0\u6d4b\u5230\u8be5\u7f51\u7ad9\u4e3a\u6076\u610f\u955c\u50cf\u7ad9\u70b9\uff0c\u5c06\u7acb\u5373\u4e3a\u60a8\u8df3\u8f6c\u5230\u5b98\u65b9\u7ad9\u70b9\uff01");location.href = location.href.replace(document.location.host,' . $currentDomain . ');}\'/>' ;
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
摘自 @曾勁鬆博客
 
/**
* 網站被惡意鏡像怎麼辦 一段代碼輕鬆搞定(全面版) - 龍笑天下
*/
add_action( 'wp_footer' , 'lxtx_kimsom_reverse_proxy_defense' );
function lxtx_kimsom_reverse_proxy_defense(){
$domain_arr = explode ( '//' ,home_url());
$domain = $domain_arr [1];
  echo '<img style="display:none" id="inlojv-rpd" src="nothing" data-url="' .home_url(). '" onerror="this.onerror=null;var str0=document.getElementById(\'inlojv-rpd\').attributes.getNamedItem(\'data-url\').nodeValue;var ishttps=\'https:\'==document.location.protocol?true:false;if(ishttps){var str1=\'https\'+\'://\';}else{var str1=\'http\'+\'://\';}var str2=\'' . $domain . '\';var str3=str1+str2;if( str0!=str3 ){alert(\'\u8b66\u544a\uff01\u68c0\u6d4b\u5230\u8be5\u7f51\u7ad9\u4e3a\u6076\u610f\u955c\u50cf\u7ad9\u70b9\uff0c\u5c06\u7acb\u5373\u4e3a\u60a8\u8df3\u8f6c\u5230\u5b98\u65b9\u7ad9\u70b9\uff01\');if (!!(window.attachEvent && !window.opera)){document.execCommand(\'stop\');}else{ window.stop();}var str4=\'wind\'+\'ow.loca\'+\'tion.rep\'+\'lace(str3)\';eval(str4);}">' ;
}
/**
* 網站被惡意鏡像怎麼辦 一段代碼輕鬆搞定(全面版) - 龍笑天下
*/
add_action( 'wp_footer' , 'lxtx_kimsom_reverse_proxy_defense' );
function lxtx_kimsom_reverse_proxy_defense(){
$domain_arr = explode ( '//' ,home_url());
$domain = $domain_arr [1];
  echo '<img style="display:none" id="inlojv-rpd" src="nothing" data-url="' .home_url(). '" onerror="this.onerror=null;var str0=document.getElementById(\'inlojv-rpd\').attributes.getNamedItem(\'data-url\').nodeValue;var ishttps=\'https:\'==document.location.protocol?true:false;if(ishttps){var str1=\'https\'+\'://\';}else{var str1=\'http\'+\'://\';}var str2=\'' . $domain . '\';var str3=str1+str2;if( str0!=str3 ){alert(\'\u8b66\u544a\uff01\u68c0\u6d4b\u5230\u8be5\u7f51\u7ad9\u4e3a\u6076\u610f\u955c\u50cf\u7ad9\u70b9\uff0c\u5c06\u7acb\u5373\u4e3a\u60a8\u8df3\u8f6c\u5230\u5b98\u65b9\u7ad9\u70b9\uff01\');if (!!(window.attachEvent && !window.opera)){document.execCommand(\'stop\');}else{ window.stop();}var str4=\'wind\'+\'ow.loca\'+\'tion.rep\'+\'lace(str3)\';eval(str4);}">' ;
}

添加以上代碼以後,再打開鏡像站就會彈出提示:「警告!檢測到該網站爲惡意鏡像站點,將當即爲您跳轉到官方站點!」,並在關閉或肯定此提示後直接跳轉到被鏡像的網站。通過本站測試,本方法防止網站被鏡像目前有效。

效果請看這裏:

https://www.ilxtx.com.dijicat.com/the-shawshank-redemption-1994.html

此方法在 IE11 上,會彈出提示框,但點擊「肯定」按鈕後,網頁並不會跳轉。。。Firefox、Chrome 和 360 極速瀏覽器上則沒此問題!

②、HTML 通用版

既然是利用 js 代碼,那麼就能用到如何 html 頁面當中了。要不是爲了能夠放到 wp 的 functions.php,都不必寫成 php 的模式,直接用 html 代碼便可:

?
1
2
3
<img style= "display:none" src= " " onerror= 'this.onerror=null;var currentDomain="www." + "ilxtx" + ".com"; var str1=currentDomain; str2="docu"+"ment.loca"+"tion.host"; str3=eval(str2) ;if( str1!=str3 && str3!="cache.baiducontent.com" && str3!="webcache.googleusercontent.com" && str3!="c.360webcache.com" && str3!="cncc.bingj.com" && str3!="snapshot.sogoucdn.com" ){ do_action = "loca" + "tion." + "href = loca" + "tion.href" + ".rep" + "lace(docu" +"ment"+".loca"+"tion.ho"+"st," + "currentDomain" + ")";eval(do_action) }' />
 
<img style= "display:none" src= " " onerror= 'this.onerror=null;var currentDomain="www." + "ilxtx" + ".com"; var str1=currentDomain; str2="docu"+"ment.loca"+"tion.host"; str3=eval(str2) ;if( str1!=str3 && str3!="cache.baiducontent.com" && str3!="webcache.googleusercontent.com" && str3!="c.360webcache.com" && str3!="cncc.bingj.com" && str3!="snapshot.sogoucdn.com" ){ do_action = "loca" + "tion." + "href = loca" + "tion.href" + ".rep" + "lace(docu" +"ment"+".loca"+"tion.ho"+"st," + "currentDomain" + ")";eval(do_action) }' />

將以上代碼中的: var currentDomain="www." + "ilxtx" + ".com"; 自行拆分紅本身的域名,避免被鏡像代碼替換掉,好比: var currentDomain="zhangge." + "net";

而後將代碼添加到網站的 <body> 以後便可(不建議放置到 <head> 裏面,具體緣由上文已說明),這個版本適合任何網頁。

方法 5:經過禁止某些 User Agent 特徵來防

服務器反爬蟲攻略:Apache/Nginx/PHP 禁止某些 User Agent 抓取網站
咱們都知道網絡上的爬蟲很是多,有對網站收錄有益的,好比百度蜘蛛(Baiduspider),也有不但不遵照 robots 規則對服務器形成壓力,還不能爲網站帶來流量的無用爬蟲,好比 YY 蜘蛛(Yis...

參考上面這篇文章來禁止 UA 爲 PHP 的抓取網頁,從而達到防鏡像的目的!

①、PHP 通用版:

將下面的代碼貼到網站入口文件 index.php 中的第一個 <?php以後便可:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//防止惡意HTTP_USER_AGENT採集
$ua = $_SERVER [ 'HTTP_USER_AGENT' ];
$now_ua = array ( 'FeedDemon ' , 'BOT/0.1 (BOT for JCE)' , 'CrawlDaddy ' , 'Java' , 'Feedly' , 'UniversalFeedParser' , 'ApacheBench' , 'Swiftbot' , 'ZmEu' , 'Indy Library' , 'oBot' , 'jaunty' , 'YandexBot' , 'AhrefsBot' , 'MJ12bot' , 'WinHttp' , 'EasouSpider' , 'HttpClient' , 'Microsoft URL Control' , 'YYSpider' , 'jaunty' , 'Python-urllib' , 'lightDeckReports Bot' , 'PHP' );
if (! $ua ) {
header( "Content-type: text/html; charset=utf-8" );
   die ( '請勿採集本站,採集者木有小JJ!請正常訪問,並認準【龍笑天下網】官方網址!' );
} else {
   foreach ( $now_ua as $value )
   if ( eregi ( $value , $ua )) {
   header( "Content-type: text/html; charset=utf-8" );
   die ( '請勿採集本站,採集者木有小JJ!請正常訪問,並認準【龍笑天下網】官方網址!' );
   }
}
 
//防止惡意HTTP_USER_AGENT採集
$ua = $_SERVER [ 'HTTP_USER_AGENT' ];
$now_ua = array ( 'FeedDemon ' , 'BOT/0.1 (BOT for JCE)' , 'CrawlDaddy ' , 'Java' , 'Feedly' , 'UniversalFeedParser' , 'ApacheBench' , 'Swiftbot' , 'ZmEu' , 'Indy Library' , 'oBot' , 'jaunty' , 'YandexBot' , 'AhrefsBot' , 'MJ12bot' , 'WinHttp' , 'EasouSpider' , 'HttpClient' , 'Microsoft URL Control' , 'YYSpider' , 'jaunty' , 'Python-urllib' , 'lightDeckReports Bot' , 'PHP' );
if (! $ua ) {
header( "Content-type: text/html; charset=utf-8" );
   die ( '請勿採集本站,採集者木有小JJ!請正常訪問,並認準【龍笑天下網】官方網址!' );
} else {
   foreach ( $now_ua as $value )
   if ( eregi ( $value , $ua )) {
   header( "Content-type: text/html; charset=utf-8" );
   die ( '請勿採集本站,採集者木有小JJ!請正常訪問,並認準【龍笑天下網】官方網址!' );
   }
}

②、Wordpress 適用版

若是使用上面的 php 版本,WordPress 每次更新就會須要操做 index.php,比較麻煩,所以弄個專版。

將下面的代碼貼到 functions.php 中的最後一個 ?>以前便可:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* 網站被惡意鏡像怎麼辦 一段代碼輕鬆搞定(全面版) - 龍笑天下
* 出自:zhange.net
*/
//防止惡意HTTP_USER_AGENT採集
add_action( 'wp_head' , 'lxtx_deny_mirrored_request' , 0);
function lxtx_deny_mirrored_request()
{
$ua = $_SERVER [ 'HTTP_USER_AGENT' ];
$now_ua = array ( 'FeedDemon ' , 'BOT/0.1 (BOT for JCE)' , 'CrawlDaddy ' , 'Java' , 'Feedly' , 'UniversalFeedParser' , 'ApacheBench' , 'Swiftbot' , 'ZmEu' , 'Indy Library' , 'oBot' , 'jaunty' , 'YandexBot' , 'AhrefsBot' , 'MJ12bot' , 'WinHttp' , 'EasouSpider' , 'HttpClient' , 'Microsoft URL Control' , 'YYSpider' , 'jaunty' , 'Python-urllib' , 'lightDeckReports Bot' , 'PHP' );
if (! $ua ) {
header( "Content-type: text/html; charset=utf-8" );
wp_die( '請勿採集本站,採集者木有小JJ!請正常訪問,並認準【龍笑天下網】官方網址!' );
} else {
   foreach ( $now_ua as $value )
   if ( eregi ( $value , $ua )) {
   header( "Content-type: text/html; charset=utf-8" );
   wp_die( '請勿採集本站,採集者木有小JJ!請正常訪問,並認準【龍笑天下網】官方網址!' );
   }
}
}
 
/**
* 網站被惡意鏡像怎麼辦 一段代碼輕鬆搞定(全面版) - 龍笑天下
* 出自:zhange.net
*/
//防止惡意HTTP_USER_AGENT採集
add_action( 'wp_head' , 'lxtx_deny_mirrored_request' , 0);
function lxtx_deny_mirrored_request()
{
$ua = $_SERVER [ 'HTTP_USER_AGENT' ];
$now_ua = array ( 'FeedDemon ' , 'BOT/0.1 (BOT for JCE)' , 'CrawlDaddy ' , 'Java' , 'Feedly' , 'UniversalFeedParser' , 'ApacheBench' , 'Swiftbot' , 'ZmEu' , 'Indy Library' , 'oBot' , 'jaunty' , 'YandexBot' , 'AhrefsBot' , 'MJ12bot' , 'WinHttp' , 'EasouSpider' , 'HttpClient' , 'Microsoft URL Control' , 'YYSpider' , 'jaunty' , 'Python-urllib' , 'lightDeckReports Bot' , 'PHP' );
if (! $ua ) {
header( "Content-type: text/html; charset=utf-8" );
wp_die( '請勿採集本站,採集者木有小JJ!請正常訪問,並認準【龍笑天下網】官方網址!' );
} else {
   foreach ( $now_ua as $value )
   if ( eregi ( $value , $ua )) {
   header( "Content-type: text/html; charset=utf-8" );
   wp_die( '請勿採集本站,採集者木有小JJ!請正常訪問,並認準【龍笑天下網】官方網址!' );
   }
}
}

通過測試,在 functions.php 中加入此代碼後,打開鏡像站後顯示「Internal Server Error」,強制刷新後顯示咱們設置好的提示文字「請勿採集本站,採集者木有小 JJ!請正常訪問,並認準【龍笑天下網】官方網址!」。

本站目前發現的惡意鏡像域名

dijicat.com
lapaleo.com
iaroex.com
disauvi.com
3s3s.org
ytlqpo.com
s3.gvirabi.com
hdtmail.com
dimyapi.com

更多鏡像網站等你提供~

在這些域名前面加上大家本身的的域名,看看有沒有被惡意鏡像。

友情提示:建議方法 2 和方法 3 一塊兒使用!方法 4 包含方法 2 和方法 3~

 

全局置頂    
     
六星教育PHP培訓視頻教程 attach_img  ...23
使用Yii2.0開發京東商城視頻教程  ...23
Yii2.0進階版高級組件ES/Redis/ Sentry優化京東平臺視頻教程  ...23
向軍laravel和vuejs webAPP實戰開發視頻教程  ...23
火星PHP基礎入門到高級開發視頻教程(含Js、Mysql實例)
ThinkPHP 5.0開發微信小程序商場打通全棧項目架構  ...2
布爾教育燕十八PHP大獅班視頻教程 attach_img
由淺入深全面揭祕微信公衆平臺開發內幕 (價值1280) attach_img
兄弟連新版PHP視頻教程(共346講)
微信公衆平臺接口二次開發搭建教程
最新PHP異步通訊框架Swoole解讀
PHP職場之面試實戰指南-面試技巧、考官思路
2018千鋒教育全套PHP視頻教程
PHP攻城獅 - PHP從基礎語法到原生項目開發 attach_img
PHP千萬級秒殺項目實戰附帶視頻講解+代碼演示+課程介紹+總結 attach_img
泰牛2017年PHP基礎班+大牛班+高級課程全套
2018優才Web PHP全棧工程師高級教程-調優-高性能-億級架構
HttpHelper萬能框架1.9.0.6源碼 attach_img
公衆號開發 公衆平臺 接口開發php 視頻教程 源碼+工具+視頻
相關文章
相關標籤/搜索