-
-
Save icai/07afa8c847d2efb2f1b613d778b3af96 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", | |
"/bot@bot.bot/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