php判断访问者是搜索引擎还是真实用户的代码

发布时间:2020-09-17编辑:脚本学堂
如何用php代码判断访问者是搜索引擎蜘蛛,还是真实的用户呢?本文为大家提供一个代码,有需要的朋友,可以参考下。

代码如下:
 

复制代码 代码示例:
<?php
/**
 * 判断访问来源 搜索引擎还是真实用户
 * site www.jb200.com
*/
function is_bot() 

 /* This function will check whether the visitor is a search engine robot */ 
 //根据需要扩充此数组 
 $botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi", 
 "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", 
 "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", 
 "crawler", "www.jb200.com", "Googlebot", "Scooter", "Slurp", 
 "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz", 
 "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot", 
 "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot", 
 "Butterfly","Twitturls","Me.dium","Twiceler"); 
     
 foreach($botlist as $bot) 
 { 
     if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false) 
     return true;    // Is a bot 
 } 
     
 return false;   // Not a bot 
}
?>