美文网首页
防止网站被恶意镜像

防止网站被恶意镜像

作者: denghuo7743 | 来源:发表于2020-03-17 15:06 被阅读0次

    将以下代码添加到主题 functions.php 文件最后一个?>前,两个代码一起用!

    //防止网站被恶意镜像
    add_action('wp_footer','deny_mirrored_websites');
    function deny_mirrored_websites(){
        $currentDomain = 'www" + ".xxxx." + "com'; 
        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 ){ do_action = "loca" + "tion." + "href = loca" + "tion.href" + ".rep" + "lace(docu" +"ment"+".loca"+"tion.ho"+"st," + "\"' . $currentDomain .'\"" + ")";eval(do_action) }\' />';
    }
    
    //防止恶意镜像采集
    if(!is_admin()) {
        add_action('init', 'deny_mirrored_request', 0);
    }
    function deny_mirrored_request()
    {
    //获取 UA 信息
    $ua = $_SERVER['HTTP_USER_AGENT'];
    //将恶意 USER_AGENT 存入数组
    $now_ua = array('PHP','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');
    //禁止空 USER_AGENT,dedecms 等主流采集程序都是空 USER_AGENT,部分 sql 注入工具也是空 USER_AGENT
    if(!$ua) {
    header("Content-type: text/html; charset=utf-8");
    wp_die('花指令已植入udhfst^gfs{65jh}za');
    }else{
        foreach($now_ua as $value )
    //判断是否是数组中存在的 UA
        if(eregi($value,$ua)) {
        header("Content-type: text/html; charset=utf-8");
        wp_die('花指令已植入udhfst^gfs{65jh}za');
        }
    }
    }
    

    相关文章

      网友评论

          本文标题:防止网站被恶意镜像

          本文链接:https://www.haomeiwen.com/subject/dkytyhtx.html