您好,欢迎访问一九零五行业门户网

php 判断访客是否为搜索引擎蜘蛛的函数代码

/** * 判断是否为搜索引擎蜘蛛 * * @author eddy * @return bool */ function iscrawler() { $agent= strtolower($_server['http_user_agent']); if (!empty($agent)) { $spidersite= array( "tencenttraveler", "baiduspider+", "baidugame", "googlebot", "msnbot", "sosospider+", "sogou web spider", "ia_archiver", "yahoo! slurp", "youdaobot", "yahoo slurp", "msnbot", "java (often spam bot)", "baiduspider", "voila", "yandex bot", "bspider", "twiceler", "sogou spider", "speedy spider", "google adsense", "heritrix", "python-urllib", "alexa (ia archiver)", "ask", "exabot", "custo", "outfoxbot/yodaobot", "yacy", "surveybot", "legs", "lwp-trivial", "nutch", "stackrambler", "the web archive (ia archiver)", "perl tool", "mj12bot", "netcraft", "msiecrawler", "wget tools", "larbin", "fish search", ); foreach($spidersite as $val) { $str = strtolower($val); if (strpos($agent, $str) !== false) { return true; } } } else { return false; } }
网上倒是能搜到一大把,不过都是千篇一律的复制来复制去的,也不够全面,我这里整理了一份比较全面的代码:
function is_spider(){ $robot = 0; $user_agent = strtolower($_server['http_user_agent']); if(strpos($user_agent,"bot")) $robot = 1; if(strpos($user_agent,"spider")) $robot = 1; if(strpos($user_agent,"slurp")) $robot = 1; if(strpos($user_agent,"mediapartners-google")) $robot = 1; if(strpos($user_agent,"fast-webcrawler")) $robot = 1; if(strpos($user_agent,"altavista")) $robot = 1; if(strpos($user_agent,"ia_archiver")) $robot = 1; if($robot == 1){ //do something } return ''; }
更多php 判断访客是否为搜索引擎蜘蛛的函数代码。
其它类似信息

推荐信息