总结一个使用 php 判断访问者是否为搜索引擎蜘蛛的函数。
/** * 判断是否为搜索引擎蜘蛛 * @return bool */ function isCrawler() { $agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : ''; if ($agent) { $spiderSite = [ 'TencentTraveler', 'Baiduspider+', 'BaiduGame', 'Googlebot', 'msnbot', 'Sosospider+', 'Sogou web spider', 'ia_archiver', 'Yahoo! Slurp', 'YoudaoBot', 'Yahoo Slurp', 'MSNBot', 'Java (Often spam bot)', 'BaiDuSpider', 'Voila', 'Yandex bot', 'BSpider', 'twiceler', 'Sogou Spider', 'Speedy Spider', 'Google AdSense', 'Heritrix', 'Python-urllib', 'Alexa (IA Archiver)', 'Ask', 'Exabot', 'Custo', 'OutfoxBot/YodaoBot', 'yacy', 'SurveyBot', 'legs', 'lwp-trivial', 'Nutch', 'StackRambler', 'The web archive (IA Archiver)', 'Perl tool', 'MJ12bot', 'Netcraft', 'MSIECrawler', 'WGet tools', 'larbin', 'Fish search' ]; foreach ($spiderSite as $val) { $str = strtolower($val); if (strpos($agent, $str) !== false) { return true; } } } return false; }