PHP 判断是否爬虫蜘蛛

0 Comment

如题,代码改自网络,记录一下。

//判断是否爬虫蜘蛛 https://gist.github.com/zhangguiqiang/2859126
if ( !function_exists( 'isCrawler' ) ) {
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(
"/spider/",
"/bot/",
"/crawl/",
"/Googlebot/",
"/Google/",
"/baidu/",
"/blogsearch/",
"/ia_archive/",
"/Slurp/",
"/Yandex/",
"/Yeti/",
"/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;
}
}
声明:除非注明,常阳时光文章均为原创
本文地址:https://cyhour.com/875/
转载时必须以链接形式注明原始出处。
Views: 81 Tags:  ,  , 

Comments:0

发表留言

炒蛋:Vultr 送$25 | 搬瓦工年付$19补货,优惠码 BWH26FXH3HIQ | 推荐VPS信息