Created
June 2, 2012 16:49
-
-
Save zhangguiqiang/2859126 to your computer and use it in GitHub Desktop.
PHP:is_crawler(判断是否是爬虫)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isCrawler() { | |
if(ini_get('browscap')) { | |
$browser= get_browser(NULL, true); | |
if($browser['crawler']) { | |
return true; | |
} | |
} else if (isset($_SERVER['HTTP_USER_AGENT'])){ | |
$agent= $_SERVER['HTTP_USER_AGENT']; | |
$crawlers= array( | |
"/Googlebot/", | |
"/Yahoo! Slurp;/", | |
"/msnbot/", | |
"/Mediapartners-Google/", | |
"/Scooter/", | |
"/Yahoo-MMCrawler/", | |
"/FAST-WebCrawler/", | |
"/Yahoo-MMCrawler/", | |
"/Yahoo! Slurp/", | |
"/FAST-WebCrawler/", | |
"/FAST Enterprise Crawler/", | |
"/grub-client-/", | |
"/MSIECrawler/", | |
"/NPBot/", | |
"/NameProtect/i", | |
"/ZyBorg/i", | |
"/worio bot heritrix/i", | |
"/Ask Jeeves/", | |
"/libwww-perl/i", | |
"/Gigabot/i", | |
"/[email protected]/i", | |
"/SeznamBot/i", | |
); | |
foreach($crawlers as $c) { | |
if(preg_match($c, $agent)) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment