网站被恶意镜像怎么办 php一段代码轻松搞定(全面版)


当前第2页 返回上一页

效果请看这里:

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

此方法在 IE11 上,会弹出提示框,但点击“确定”按钮后,网页并不会跳转。。。Firefox、Chrome 和 360 极速浏览器上则没此问题!

②、HTML 通用版

既然是利用 js 代码,那么就能用到如何 html 页面当中了。要不是为了可以放到 wp 的 functions.php,都没必要写成 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";

然后将代码添加到网站的 <body> 之后即可(不建议放置到 <head> 里面,具体原因上文已说明),这个版本适合任何网页。

方法 5:通过禁止某些 User Agent 特征来防

服务器反爬虫攻略:Apache/Nginx/PHP 禁止某些 User Agent 抓取网站
我们都知道网络上的爬虫非常多,有对网站收录有益的,比如百度蜘蛛(Baiduspider),也有不但不遵守 robots 规则对服务器造成压力,还不能为网站带来流量的无用爬虫,比如 YY 蜘蛛(Yis...

参考上面这篇文章来禁止 UA 为 PHP 的抓取网页,从而达到防镜像的目的!

①、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!请正常访问,并认准【龙笑天下网】官方网址!');
  }
}

//防止恶意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 中的最后一个 ?>之前即可:

/**
* 网站被恶意镜像怎么办 一段代码轻松搞定(全面版) - 龙笑天下
* 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('请勿采集本站,采集者木有小JJ!请正常访问,并认准【龙笑天下网】官方网址!');
}else{
  foreach($now_ua as $value )
  if(eregi($value,$ua)) {
  header("Content-type: text/html; charset=utf-8");
  wp_die('请勿采集本站,采集者木有小JJ!请正常访问,并认准【龙笑天下网】官方网址!');
  }
}
}

/**
* 网站被恶意镜像怎么办 一段代码轻松搞定(全面版) - 龙笑天下
* 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('请勿采集本站,采集者木有小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~


标签:WordPress

返回前面的内容

相关阅读 >>

php多用户博客系统分析[想做多用户博客的朋友,需要了解]

centos下如何合并目录centos下合并目录的方法

wordpress开发中的get_post_custom()函数使用解析

wordpress插件的使用

#实践笔记#本地配置phpnow与wordpress运行环境

用python写的一个wordpress的采集程序

老鹰主机一键安装wordpress建站的方法(图文教程)

wordpress实现网站投稿者也可以上传图片的方法

wordpress简单三步实现首页文章显示缩略图(无插件)

wordpress随机文章随机推荐的实现思路与用法

更多相关阅读请进入《wordpress》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...