向来都有去百度统计查看的习惯,今日不料被我发现一个坏东西竟然镜像,实在可恶!
然后心里一笑本宝宝辣么荣幸,还有镜像本站的。随之就去各种询问...终于找到了好几个比较简单粗暴的..
接下来给你们分享一下这几种使用简单粗暴的防镜像神器,个人觉得放在底部文件footer.PHP比较合适其余不多说直接上代码。。
JS版本
<script type="text/javascript"> if(location.toString().indexOf("amuker.com")<=-1){document.location.href="http://www.amuker.com";} </script>
<script> if (document.domain != 'www.XXX.com'){ window.location.href='http://www.XXXX.com/';} </script>
<script type="text/javascript">
if (document.location.host != "www.XXX.com") { location.href = location.href.replace(document.location.host,'www.XXX.com'); } </script>
<script type="text/javascript"> if (document.location.protocol != "https:" && navigator.userAgent.indexOf("MSIE 6.0") < 0 ) { location.href = location.href.replace(/^http:/,"https:");}if (document.location.host != "www.XXX.com") { location.href = location.href.replace(document.location.host,'www.XXX.com);} </script>
JS代码被屏蔽后解决方法
<div style="display:none;"> <script>proxy2016 = false;</script> <img src=" " onerror='setTimeout(function(){if(typeof(proxy2016)=="undefined"){window.location.host="XXXX.com";}},3000);'> </div>
PHP通用版本
将下面的代码贴到网站入口文件index.php中的第一个 <?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('请勿采集本站,采集者木有小JJ!请正常访问!'); }else{ foreach($now_ua as $value ) if(eregi($value,$ua)) { header("Content-type: text/html; charset=utf-8"); die('请勿采集本站,采集者木有小JJ!请正常访问!'); } }
第二种PHP方法,这种方法好,但是不不给代码,嘿嘿,劳动最光荣,请自己手打!学习PHP就是要多动手。
复制代码后记得更换域名!
---
转载请注明本文标题和链接:《最强PHP防镜像防采集代码收集,简单粗暴...你值得拥有》