PHP判斷來訪是蜘蛛還是普通使用者_PHP教程

來源:互聯網
上載者:User
準備開始做正規的SEO,黑鏈代碼依舊是用,只是有點特殊而已,當然,自己先測試下,是否可行。
要弄個PHP文檔,記錄來訪是否蜘蛛還是普通使用者,具體就是根據php的$_SERVER['HTTP_USER_AGENT']來進行判斷
具體代碼如下:

$tmp = $_SERVER['HTTP_USER_AGENT'];
if(strpos($tmp, 'Googlebot') !== false){
echo 'Google';
} 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';
}
?>
以下來自百度,當然,以上也來自百度。我只是負責文章“偽原創”

www.2cto.com

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

摘自 http://www.xssxss.com/fuck/505.xss

http://www.bkjia.com/PHPjc/478470.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478470.htmlTechArticle準備開始做正規的SEO,黑鏈代碼依舊是用,只是有點特殊而已,當然,自己先測試下,是否可行。 要弄個PHP文檔,記錄來訪是否蜘蛛還是普...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.