/** * Judging whether the search engine spider * * @author Eddy * @return bool */function Iscrawler () {$agent = s Trtolower ($_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 b OT) "," Baiduspider "," Voila "," Yandex bot "," Bspider "," Twiceler "," Sogou spider "," Speedy spider "," Google AdSense "," her Itrix "," Python-urllib "," Alexa (IA archiver) "," Ask "," Exabot "," Custo "," Outfoxbot/yodaobot "," YaCy "," Surveybot "," leg S "," lwp-trivial "," Nutch "," Stackrambler "," The Web Archive (IA archiver) "," Perl Tool "," Mj12bot "," Netcraft "," Msiecraw Ler "," WGet Tools "," Larbin "," Fish Search ",); foreach ($spiderSite as $val) {$str = Strtolower ($val), if (Strpos ($agent, $STR)!== false) {return true;}} else {return false;}}
Online is able to search a lot of, but are the same-made copy to copy to, and not comprehensive enough, I have compiled a more comprehensive code here:
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 '; }