We can judge whether it is a spider by http_user_agent, the spider of search engine has its own unique symbol, the following list takes part. functionIs_crawler () {$userAgent=Strtolower($_server[' Http_user_agent ']); $spiders=Array( ' Googlebot ',//Google crawler' Baiduspider ',//Baidu Crawler' Yahoo! slurp ',//Yahoo crawler' Yodaobot ',//Youdao crawler' MSNBot '//Bing Crawler//More crawler keywords ); foreach($spiders as $spider) { $spider=Strtolower($spider); if(Strpos($userAgent,$spider) !==false) { return true; } } return false;} The following PHP code comes with more spider logosfunctionIscrawler () {Echo $agent=Strtolower($_server[' Http_user_agent ']); if(!Empty($agent)) { $spiderSite=Array( "Tencenttraveler", "baiduspider+", "Baidugame", "Goog Lebot "," MSNBot "," sosospider+ "," Sogou web Spider ", "Ia_archiver", "Yahoo! slurp", "Youdaobot", "Yahoo slurp", "MSNBot", "Java (Often spam bot)", "Baiduspider", "Voila", "Yandex bot", "BSp Ider "," 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; }}if(Iscrawler ()) {Echo"Hello Spider-Fine!" ";}Else{ Echo"You're not a Spider-Man!" ";}
PHP to determine whether a visitor is a search engine spider