solutionweb

WordPress Common Errors and Solutions

WordPress practical scheme tutorial to prevent websites from being mirrored.

1. picture onerror and js code scheme

By splitting the domain name link and comparing it with the mirror station, and then using the null value of img tag src to trigger onerror to perform js comparison, if the comparison fails, it will jump back to the source station.

The code is as follows: (Copy and paste the last one of functions.php in the theme? > before)

add_action(‘wp_footer’,’deny_mirrored_websites’);
function deny_mirrored_websites(){
$currentDomain = ‘luoxiao123.” + “cn’; //Just split your own domain name here.
echo ‘‘;
}
Html static version
It’s a variant of the above, but it’s written in static code to uninstall js. Put the following


Both of the above schemes need to replace the domain name in the code with your own domain name!
2. UA judgment scheme

Judging that UA is empty or contains a php request through PHP, otherwise a prompt pops up and it is forbidden to open.

/**
* WordPress prohibits UA from being empty or containing PHP requests.
**/
if(! is_admin()) {
add_action(‘init’, ‘deny_mirrored_request’, 0);
}
function deny_mirrored_request()
{
$ua = $_SERVER[‘HTTP_USER_AGENT’];
if(! $ua || preg_match(‘/PHP/i’, $ua)) {
header(“Content-type: text/html; charset=utf-8”);
Wp_die (‘Please don’t collect this site, because the webmaster who collects it has no small penis!’ );
}
}
Determine more request styles:

/**
* What if the website is maliciously mirrored? A piece of code can be easily done (full version)-

*/
//prevent malicious HTTP_USER_AGENT collection.
add_action(‘wp_head’, ‘deny_mirrored_request’, 0);
function 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 (‘Please don’t collect this site, the collector has no penis! Please visit normally, and!’ );
}else{
foreach($now_ua as $value )
if(eregi($value,$ua)) {
header(“Content-type: text/html; charset=utf-8”);
Wp_die (‘Please don’t collect this site, the collector has no penis! Please visit normally!’ );
}
}
}
These are the two schemes! Of course, there are methods such as nginx and. htaccess! Everyone can use it together! There are many methods, welcome comments, and share more practical and effective methods to prevent mirror image stations!

Back to top