php判断蜘蛛函数

林涛 1616℃ 0评论

PHP写的判定是否为“蜘蛛”(爬虫)数据的函数:

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;
}

如需转载请注明: 转载自26点的博客

本文链接地址: php判断蜘蛛函数

转载请注明:26点的博客 » php判断蜘蛛函数

喜欢 (0)
发表我的评论
取消评论

表情