網(wǎng)站被惡意鏡像怎么辦 php一段代碼輕松搞定(全面版)
有時(shí)候你會(huì)發(fā)現(xiàn),你在搜索引擎輸入網(wǎng)站名稱(chēng)的時(shí)候,出來(lái)的網(wǎng)站信息是你們的,但是域名卻是一個(gè)陌生的,這種情況可以基本確定網(wǎng)站被鏡像了,那么究竟什么叫網(wǎng)站被鏡像?
惡意鏡像,也叫惡意克隆,惡意解析,是指有人通過(guò)域名 A 記錄直接解析別人 IP 地址,從而得到一個(gè)在訪(fǎng)問(wèn)者眼中完全相同網(wǎng)站的過(guò)程。其工作原理基本上是這樣子的:有用戶(hù)訪(fǎng)問(wèn)鏡像站點(diǎn)時(shí),程序就會(huì)來(lái)正版的站點(diǎn)查詢(xún)數(shù)據(jù),并修改相關(guān)鏈接然后呈獻(xiàn)給用戶(hù),實(shí)質(zhì)上還是在讀取原站的數(shù)據(jù)。嚴(yán)謹(jǐn)一點(diǎn)的解釋?zhuān)和ㄟ^(guò)復(fù)制整個(gè)網(wǎng)站或部分網(wǎng)頁(yè)內(nèi)容并分配以不同域名和服務(wù)器,以此欺騙搜索引擎對(duì)同一站點(diǎn)或同一頁(yè)面進(jìn)行多次索引的行為 。
網(wǎng)站被鏡像的危害
通俗的講,惡意鏡像者意圖利用自己有一定權(quán)重的域名進(jìn)行威壓,通過(guò)某些手段復(fù)制了你的站點(diǎn),除了域名不一樣之外,其他內(nèi)容一模一樣,用戶(hù)或許根本無(wú)法分辨。甚至對(duì)于一些新的站點(diǎn),搜索引擎都會(huì)迷惑到底哪個(gè)是真的站點(diǎn),那么就有可能正牌的網(wǎng)站被刪除收錄,而盜版的卻被搜索引擎青睞。
雖然目前我們還不知道惡意鏡像我們的網(wǎng)站到底有什么意圖,但肯定對(duì)我們沒(méi)什么好處,如果他這個(gè)域名有點(diǎn)什么不健康的信息,那么我們被鏡像的站點(diǎn)有可能被污染掉,所以還是要警惕這個(gè)現(xiàn)象。
如何知道自己的網(wǎng)站是否被鏡像
復(fù)制自己網(wǎng)站的完整標(biāo)題(PS:查看自己站點(diǎn)首頁(yè)源碼,其中 <title>龍笑天下 - 分享悲傷;共享快樂(lè)</title>),然后在谷歌和百度等搜索引擎里搜索,如搜索:intitle 龍笑天下 - 分享悲傷;共享快樂(lè),如果有其他網(wǎng)站的網(wǎng)站標(biāo)題、描述及網(wǎng)站內(nèi)容跟你的一樣,只有域名不一樣,那就是被鏡像了。
如何處理網(wǎng)站被鏡像
這類(lèi)鏡像看似一個(gè)完整的站點(diǎn),其實(shí)上是每次用戶(hù)訪(fǎng)問(wèn)鏡像站點(diǎn),程序就會(huì)來(lái)正版的站點(diǎn)查詢(xún)數(shù)據(jù),并修改相關(guān)鏈接然后呈獻(xiàn)給用戶(hù)。實(shí)質(zhì)上還是在讀取原站的數(shù)據(jù)。以下龍笑天下就列舉幾種解決方法,大家自行取舍使用!
方法 1:查清鏡像網(wǎng)站的主機(jī) Ip,通過(guò)禁止 Ip 來(lái)解決
本教程基于 WordPress 程序,其他系統(tǒng)請(qǐng)自測(cè)!
1、獲取鏡像服務(wù)器 ip。注:這個(gè) IP 可能不是 ping 到他域名的 IP
復(fù)制如下代碼,新建一個(gè) php 文件,并命名為“ip.php”上傳到你的網(wǎng)站根目錄。
<?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); ?>
2、然后訪(fǎng)問(wèn)你網(wǎng)站的鏡像站點(diǎn),在地址后面加.../ip.php,然后你就會(huì)在網(wǎng)站根目錄找到 ip.txt 文件了,打開(kāi)復(fù)制里面的 ip 地址。
3、然后打開(kāi)你的.htaccess 文件,在后面加上如下代碼(自行修改為剛剛獲得的 ip)
#添加IP黑名單 Order Deny,Allow Deny from 162.158.72.179 #添加IP黑名單 Order Deny,Allow Deny from 162.158.72.179
當(dāng)然,如果你使用 CDN,可以直接在 CDN 后臺(tái)添加 ip 黑名單
這個(gè)時(shí)候你再刷新一下鏡像站點(diǎn),是不是已經(jīng) 403 報(bào)錯(cuò)了呢?這個(gè)時(shí)候已經(jīng)解決了這個(gè)鏡像站點(diǎn),然后就等待蜘蛛將其解決掉吧。
此方法的缺點(diǎn)就是如果鏡像網(wǎng)站更換了 ip,那我們的屏蔽就失敗了
方法 2:JS 來(lái)防護(hù)
在頭部標(biāo)簽:取自 @boke112 導(dǎo)航
<head></head>
<head></head>
里加上下面的 JS 代碼:
<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 代碼:
<script type="text/javascript">
rthost = window.location.host;
if (rthost != "www.ilxtx.com") {
top.location.;
}
</script>
<script type="text/javascript">
rthost = window.location.host;
if (rthost != "www.ilxtx.com") {
top.location.;
}
</script>
注意:將上面代碼中的www.ilxtx.com改為你網(wǎng)站的首頁(yè)主地址,如果我上面填寫(xiě)的不是我網(wǎng)站的主地址 www.ilxtx.com,而是 ilxtx.com 的話(huà),就會(huì)導(dǎo)致網(wǎng)站一直刷新!
注:經(jīng)過(guò)本站測(cè)試,如果鏡像站屏蔽了 JS,則該方法失效。所以,最好把方法 2 和方法 3 結(jié)合使用!
方法 3:Js 被屏蔽后防止鏡像的方法
將以下代碼加到網(wǎng)站的 header.php 中:代碼取自 @boke112
<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>
有些網(wǎng)站會(huì)屏蔽掉 JS 代碼(如下面的代碼) :
<script>...</script> <script>...</script>
所以 <script>proxy2016 = false;</script> 代碼將被過(guò)濾掉,img 的 onerror 設(shè)置超時(shí)時(shí)間 3000 毫秒,將運(yùn)行函數(shù)部分,檢測(cè)是否還存在 proxy2016 字符,如果沒(méi)有找到就會(huì)將主機(jī)的 URL 改為 www.ilxtx.com;為了安全起見(jiàn),將 js 部分可以使用 js 代碼混淆(本站“JS 代碼混淆” 工具 或 站長(zhǎng)之家 JS 混淆工具)。
本站的混淆結(jié)果如下:
<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>
經(jīng)過(guò)我的測(cè)試,此代碼在 Chrome、IE11 和 360 極速瀏覽器上均有效,會(huì)跳轉(zhuǎn)到源站的原文章頁(yè)!在 Firefox 上則無(wú)效果,鏡像的文章頁(yè)并不會(huì)跳轉(zhuǎn)到原站...... 將代碼中 img 標(biāo)簽的 src 引用地址改為空格或無(wú)效的圖片地址后,在 Firefox 上也起作用了!
方法 4:借助 Img 的 Onerror 事件
20161119 更新(增加搜狗快照支持):此方法使用了后,會(huì)導(dǎo)致百度快照、谷歌快照、必應(yīng)快照和搜狗快照等跳到 404 頁(yè)面(360 搜索快照則不會(huì)~),奈何不知怎么弄,2016-11-10 再次經(jīng)過(guò)張戈的指導(dǎo),將原代碼中的: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" ) 。估計(jì)要等快照更新時(shí)才能知道效果了!
20161127:經(jīng)過(guò)驗(yàn)證,上述更新已經(jīng)起作用了!具體效果,請(qǐng)點(diǎn)我~
20171022 更新:從張戈那看到,這段代碼會(huì)因?yàn)?onerror 死循環(huán)造成瀏覽網(wǎng)頁(yè)的電腦高負(fù)載(CPU 飆升),因此在代碼 onerror 觸發(fā)事件中加入 onerror 清空機(jī)制,即加入this.onerror=null?!静┛途W(wǎng)頁(yè)導(dǎo)致電腦 CPU 飆升的問(wèn)題解決記錄】
通過(guò)拆分域名鏈接與鏡像站比對(duì),然后用 img 標(biāo)簽 src 空值觸發(fā) onerror 來(lái)執(zhí)行 js 比對(duì),比對(duì)失敗則跳轉(zhuǎn)回源站。
①、WordPress 專(zhuān)用版
經(jīng)過(guò) @張戈 童學(xué)的不斷改進(jìn)(IE 不支持 window.stop() 函數(shù),所以“20160909 版本”失效...),已經(jīng)完美的適配 Firefox、Chrome、IE11 和 360 極速瀏覽器,而且可以跳轉(zhuǎn)至源站的相應(yīng)文章頁(yè),在此衷表感謝!下面 3 段任選一個(gè)即可。效果請(qǐng)看這里:http://www.ilxtx.com.3s3s.org/the-shawshank-redemption-1994.html
代碼如下:(復(fù)制粘貼到主題的 functions.php 最后一個(gè)?>之前)
/**
* 網(wǎng)站被惡意鏡像怎么辦 一段代碼輕松搞定(全面版) - 龍笑天下
* https://www.ilxtx.com/mirrored-website.html
* 最后更新時(shí)間:20171022 發(fā)布時(shí)間: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) }\' />';
}
/**
* 網(wǎng)站被惡意鏡像怎么辦 一段代碼輕松搞定(全面版) - 龍笑天下
* https://www.ilxtx.com/mirrored-website.html
* 最后更新時(shí)間:20171022 發(fā)布時(shí)間: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,經(jīng)過(guò)測(cè)試發(fā)現(xiàn)圖片放到 head,瀏覽器會(huì)自動(dòng)進(jìn)行錯(cuò)誤調(diào)整,導(dǎo)致一些本來(lái)在 head 的元素被丟到了 body 當(dāng)中,比如 style.css,估計(jì)網(wǎng)頁(yè)標(biāo)準(zhǔn)中 head 里面就不應(yīng)該放置圖片,所以移到了 footer 當(dāng)中。
/**
* 網(wǎng)站被惡意鏡像怎么辦 一段代碼輕松搞定(全面版) - 龍笑天下
* https://www.ilxtx.com/mirrored-website.html
* 出自: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) }" />';
}
/**
* 網(wǎng)站被惡意鏡像怎么辦 一段代碼輕松搞定(全面版) - 龍笑天下
* https://www.ilxtx.com/mirrored-website.html
* 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 版本”一樣有個(gè)提示語(yǔ),可將上面這段代碼改為此
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 .');}\'/>';
}
摘自 @曾勁松博客
/**
* 網(wǎng)站被惡意鏡像怎么辦 一段代碼輕松搞定(全面版) - 龍笑天下
* https://www.ilxtx.com/mirrored-website.html
*/
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);}">';
}
/**
* 網(wǎng)站被惡意鏡像怎么辦 一段代碼輕松搞定(全面版) - 龍笑天下
* https://www.ilxtx.com/mirrored-website.html
*/
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);}">';
}
添加以上代碼之后,再打開(kāi)鏡像站就會(huì)彈出提示:“警告!檢測(cè)到該網(wǎng)站為惡意鏡像站點(diǎn),將立即為您跳轉(zhuǎn)到官方站點(diǎn)!”,并在關(guān)閉或確定此提示后直接跳轉(zhuǎn)到被鏡像的網(wǎng)站。經(jīng)過(guò)本站測(cè)試,本方法防止網(wǎng)站被鏡像目前有效。
效果請(qǐng)看這里:
https://www.ilxtx.com.dijicat.com/the-shawshank-redemption-1994.html
此方法在 IE11 上,會(huì)彈出提示框,但點(diǎn)擊“確定”按鈕后,網(wǎng)頁(yè)并不會(huì)跳轉(zhuǎn)。。。Firefox、Chrome 和 360 極速瀏覽器上則沒(méi)此問(wèn)題!
②、HTML 通用版
既然是利用 js 代碼,那么就能用到如何 html 頁(yè)面當(dāng)中了。要不是為了可以放到 wp 的 functions.php,都沒(méi)必要寫(xiě)成 php 的模式,直接用 html 代碼即可:
<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";
然后將代碼添加到網(wǎng)站的 <body> 之后即可(不建議放置到 <head> 里面,具體原因上文已說(shuō)明),這個(gè)版本適合任何網(wǎng)頁(yè)。
方法 5:通過(guò)禁止某些 User Agent 特征來(lái)防
服務(wù)器反爬蟲(chóng)攻略:Apache/Nginx/PHP 禁止某些 User Agent 抓取網(wǎng)站
我們都知道網(wǎng)絡(luò)上的爬蟲(chóng)非常多,有對(duì)網(wǎng)站收錄有益的,比如百度蜘蛛(Baiduspider),也有不但不遵守 robots 規(guī)則對(duì)服務(wù)器造成壓力,還不能為網(wǎng)站帶來(lái)流量的無(wú)用爬蟲(chóng),比如 YY 蜘蛛(Yis...
參考上面這篇文章來(lái)禁止 UA 為 PHP 的抓取網(wǎng)頁(yè),從而達(dá)到防鏡像的目的!
①、PHP 通用版:
將下面的代碼貼到網(wǎng)站入口文件 index.php 中的第一個(gè) <?php之后即可:
//防止惡意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('請(qǐng)勿采集本站,采集者木有小JJ!請(qǐng)正常訪(fǎng)問(wèn),并認(rèn)準(zhǔn)【龍笑天下網(wǎng)】官方網(wǎng)址!');
}else{
foreach($now_ua as $value )
if(eregi($value,$ua)) {
header("Content-type: text/html; charset=utf-8");
die('請(qǐng)勿采集本站,采集者木有小JJ!請(qǐng)正常訪(fǎng)問(wèn),并認(rèn)準(zhǔn)【龍笑天下網(wǎng)】官方網(wǎng)址!');
}
}
//防止惡意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('請(qǐng)勿采集本站,采集者木有小JJ!請(qǐng)正常訪(fǎng)問(wèn),并認(rèn)準(zhǔn)【龍笑天下網(wǎng)】官方網(wǎng)址!');
}else{
foreach($now_ua as $value )
if(eregi($value,$ua)) {
header("Content-type: text/html; charset=utf-8");
die('請(qǐng)勿采集本站,采集者木有小JJ!請(qǐng)正常訪(fǎng)問(wèn),并認(rèn)準(zhǔn)【龍笑天下網(wǎng)】官方網(wǎng)址!');
}
}
②、Wordpress 適用版
如果使用上面的 php 版本,WordPress 每次更新就會(huì)需要操作 index.php,比較麻煩,因此弄個(gè)專(zhuān)版。
將下面的代碼貼到 functions.php 中的最后一個(gè) ?>之前即可:
/**
* 網(wǎng)站被惡意鏡像怎么辦 一段代碼輕松搞定(全面版) - 龍笑天下
* https://www.ilxtx.com/mirrored-website.html
* 出自: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('請(qǐng)勿采集本站,采集者木有小JJ!請(qǐng)正常訪(fǎng)問(wèn),并認(rèn)準(zhǔn)【龍笑天下網(wǎng)】官方網(wǎng)址!');
}else{
foreach($now_ua as $value )
if(eregi($value,$ua)) {
header("Content-type: text/html; charset=utf-8");
wp_die('請(qǐng)勿采集本站,采集者木有小JJ!請(qǐng)正常訪(fǎng)問(wèn),并認(rèn)準(zhǔn)【龍笑天下網(wǎng)】官方網(wǎng)址!');
}
}
}
/**
* 網(wǎng)站被惡意鏡像怎么辦 一段代碼輕松搞定(全面版) - 龍笑天下
* https://www.ilxtx.com/mirrored-website.html
* 出自: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('請(qǐng)勿采集本站,采集者木有小JJ!請(qǐng)正常訪(fǎng)問(wèn),并認(rèn)準(zhǔn)【龍笑天下網(wǎng)】官方網(wǎng)址!');
}else{
foreach($now_ua as $value )
if(eregi($value,$ua)) {
header("Content-type: text/html; charset=utf-8");
wp_die('請(qǐng)勿采集本站,采集者木有小JJ!請(qǐng)正常訪(fǎng)問(wèn),并認(rèn)準(zhǔn)【龍笑天下網(wǎng)】官方網(wǎng)址!');
}
}
}
經(jīng)過(guò)測(cè)試,在 functions.php 中加入此代碼后,打開(kāi)鏡像站后顯示“Internal Server Error”,強(qiáng)制刷新后顯示我們?cè)O(shè)置好的提示文字“請(qǐng)勿采集本站,采集者木有小 JJ!請(qǐng)正常訪(fǎng)問(wèn),并認(rèn)準(zhǔn)【龍笑天下網(wǎng)】官方網(wǎng)址!”。
本站目前發(fā)現(xiàn)的惡意鏡像域名
dijicat.com
lapaleo.com
iaroex.com
disauvi.com
3s3s.org
ytlqpo.com
s3.gvirabi.com
hdtmail.com
dimyapi.com
更多鏡像網(wǎng)站等你提供~
在這些域名前面加上你們自己的的域名,看看有沒(méi)有被惡意鏡像。
友情提示:建議方法 2 和方法 3 一起使用!方法 4 包含方法 2 和方法 3~
相關(guān)文章
關(guān)于PHP中Session文件過(guò)多的問(wèn)題及session文件保存位置
PHP的默認(rèn)機(jī)制:每一次php請(qǐng)求,會(huì)有1/100的概率(默認(rèn)值)觸發(fā)“session回收”。接下來(lái)通過(guò)本文給大家介紹關(guān)于PHP中Session文件過(guò)多的問(wèn)題及session文件保存位置,需要的朋友參考下2016-03-03
Laravel框架執(zhí)行原生SQL語(yǔ)句及使用paginate分頁(yè)的方法
這篇文章主要介紹了Laravel框架執(zhí)行原生SQL語(yǔ)句及使用paginate分頁(yè)的方法,以類(lèi)函數(shù)的形式給出了Laravel框架執(zhí)行原生SQL語(yǔ)句以及paginate分頁(yè)的相關(guān)操作技巧,需要的朋友可以參考下2018-08-08
Thinkphp框架+Layui實(shí)現(xiàn)圖片/文件上傳功能分析
PHP在網(wǎng)頁(yè)中動(dòng)態(tài)生成PDF文件詳細(xì)教程
Laravel框架實(shí)現(xiàn)的使用smtp發(fā)送郵件功能示例
布隆過(guò)濾器(bloom filter)及php和redis實(shí)現(xiàn)布隆過(guò)濾器的方法
Laravel 自動(dòng)生成驗(yàn)證的實(shí)例講解:login / logout

