Ps:如果是丢到 wp_head,经过测试发现图片放到 head,浏览器会自动进行错误调整,导致一些本来在 head 的元素被丢到了 body 当中,比如 style.css,估计网页标准中 head 里面就不应该放置图片,所以移到了 footer 当中。
/** * 网站被恶意镜像怎么办 一段代码轻松搞定(全面版) - 龙笑天下 * 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 src="https://www.jb51.net/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) }" />'; }
/** * 网站被恶意镜像怎么办 一段代码轻松搞定(全面版) - 龙笑天下 * 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 src="https://www.jb51.net/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 版本”一样有个提示语,可将上面这段代码改为此
add_action('wp_footer','lxtx_kimsom_reverse_proxy_defense', 99); function lxtx_kimsom_reverse_proxy_defense(){ $currentDomain = '"www." + "ilxtx" + ".com"'; echo '<img src="https://www.jb51.net/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 .');}\'/>'; }
摘自 @曾劲松博客 /** * 网站被恶意镜像怎么办 一段代码轻松搞定(全面版) - 龙笑天下 * 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 src="https://www.jb51.net/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/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 src="https://www.jb51.net/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);}">'; }