Home >Web Front-end >JS Tutorial >Determine spider code black hat jump code based on user-agent (js version and php version)_javascript skills
There is a trick that everyone is using in black hat SEO methods. The server determines the user-agent of the client browser and then performs further operations.
There are always people using this code on the Internet. First, it is a js code to determine where the website visitor comes from. If it comes from a search engine, it will jump. If it is a direct access, it will not change. This code was found from the Internet for a long time. Thank you for the original Author
<script language="javascript"> var pattern = /google/gi; var pattern1= /yahoo/gi; var keyValue=escape(document.referrer); if (pattern.exec(keyValue)) setTimeout( "windows.location='http://www.jb51.net'",10*1000); else if(pattern1.exec(keyValue)) setTimeout( "window.location='http://www.jb51.net'",10*1000); </script>
If it is the user-agent of a search engine, it will be redirected by 301. Currently, many people on the Internet use this method to cheat friendly links (the code will be placed at the end)
There are many more specific ideas, jump, Qiao page, etc. Today I will only release the code. PHP code
Statement: The codes are all from Baidu. Let’s write a simple one first
Determine based on php's $_SERVER['HTTP_USER_AGENT']
<?php $tmp = $_SERVER['HTTP_USER_AGENT']; if(strpos($tmp, 'Googlebot') !== false){ echo '谷歌'; } else if(strpos($tmp, 'Baiduspider') >0){ echo '百度'; } else if(strpos($tmp, 'Yahoo! Slurp') !== false){ echo '雅虎'; } else if(strpos($tmp, 'msnbot') !== false){ echo 'Msn'; } else if(strpos($tmp, 'Sosospider') !== false){ echo '搜搜'; } else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){ echo '有道'; } else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){ echo '搜狗'; } else if(strpos($tmp, 'fast-webcrawler') !== false){ echo 'Alltheweb'; } else if(strpos($tmp, 'Gaisbot') !== false){ echo 'Gais'; } else if(strpos($tmp, 'ia_archiver') !== false){ echo 'Alexa'; } else if(strpos($tmp, 'altavista') !== false){ echo 'AltaVista'; } else if(strpos($tmp, 'lycos_spider') !== false){ echo 'Lycos'; } else if(strpos($tmp, 'Inktomi slurp') !== false){ echo 'Inktomi'; } ?>
Second paragraph with jump
<?php $flag = false; $tmp = $_SERVER['HTTP_USER_AGENT']; if(strpos($tmp, 'Googlebot') !== false){ $flag = true; } else if(strpos($tmp, 'Baiduspider') >0){ $flag = true; } else if(strpos($tmp, 'Yahoo! Slurp') !== false){ $flag = true; } else if(strpos($tmp, 'msnbot') !== false){ $flag = true; } else if(strpos($tmp, 'Sosospider') !== false){ $flag = true; } else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){ $flag = true; } else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){ $flag = true; } else if(strpos($tmp, 'fast-webcrawler') !== false){ $flag = true; } else if(strpos($tmp, 'Gaisbot') !== false){ $flag = true; } else if(strpos($tmp, 'ia_archiver') !== false){ $flag = true; } else if(strpos($tmp, 'altavista') !== false){ $flag = true; } else if(strpos($tmp, 'lycos_spider') !== false){ $flag = true; } else if(strpos($tmp, 'Inktomi slurp') !== false){ $flag = true; } if($flag == false){ header("Location: http://www.jb51.net" . $_SERVER['REQUEST_URI']); // 自动转到http://www.jb51.net 对应的网页 // $_SERVER['REQUEST_URI'] 为域名后面的路径 // 或 换成 header("Location: http://www.jb51.net/abc/d.php"); exit(); } ?>
The third piece of code is a 301 jump after judgment
if (preg_match(“#(google|slurp@inktomi|yahoo! slurp|msnbot)#si”, $_SERVER['HTTP_USER_AGENT'])) { header(“HTTP/1.1 301 Moved Permanently”); header(“Location: http://www.saoyu.com/”); exit; }}
Black hat methods are risky, please use them with caution. If the friends who are tricked feel that they are looking for a backdoor.