如果我只设置Google Bot;我可以使用以下代码进行此设置:
if(!strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
{
if($_SERVER["HTTP_CF_IPCOUNTRY"] =! 'USA')
{
echo "empty";
die();
}
}
但我想添加yandexbot和bingbot ......我怎么设置?
答案 0 :(得分:0)
我为你做了一个阵列。它有你最喜欢的机器人,如googlebot,yahoo和yandex。如果需要,您还可以通过逗号分隔的单引号中的Crawlerlist数组添加任何额外的useragent。
您可以在此处获取所有可用的UserAgent列表:http://www.useragentstring.com/pages/Crawlerlist/
$UserAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
$Crawlerlist = array('googlebot', 'yahoo','yandex');
$pattern = '/('.implode('|', $Crawlerlist).')/';
if(preg_match($pattern,$UserAgent))
echo "Do something on the Website when either one of above 3 bots are matched";
else
echo "Do Nothing when Not matched";
我希望这会对你有所帮助。这是我在Stack Overflow中的第一个答案。