有没有办法检测机器人是否访问过该页面?
我尝试检查$_SERVER['HTTP_USER_AGENT']
是否在数组中。它工作正常。
$bot = array("Slurp", "Scooter", "URL_Spider_SQL", "Googlebot", "Firefly", "WebBug", "WebFindBot", "crawler", "appie", "msnbot", "InfoSeek", "FAST", "Spade", "NationalDirectory",);
if (in_array($_SERVER['HTTP_USER_AGENT'], $bot)) {
return true;
}
else {
return false;
}
有更好更安全的方法吗? (除了必须键入所有机器人名称?)我的方法与this之间有什么区别?
答案 0 :(得分:2)
好吧,经过对Google内部的一些挖掘后,我发现了这一点。
$agent = strpos(strtolower($_SERVER['HTTP_USER_AGENT']));
foreach($bots as $name => $bot)
{
if(stripos($agent,$bot)!==false)
{
return true;
}
else {
return false;
}
}
感谢Dale的支持!!
答案 1 :(得分:0)
查看Sid的答案,然后使用谷歌搜索this site以其他方式检测到。看:
function detect_is_bot () {
$bots = array("Slurp", "Scooter", "URL_Spider_SQL", "Googlebot", "Firefly", "WebBug", "WebFindBot", "crawler", "appie", "msnbot", "InfoSeek", "FAST", "Spade", "NationalDirectory",);
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
foreach($bots as $bot) {
if(stripos($agent,$bot)!==false) {return true;}
}
return false;
}