1

If I set to only Google Bot; I can this setting with this code:

if(!strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
{
    if($_SERVER["HTTP_CF_IPCOUNTRY"] =! 'USA')
    { 
       echo "empty";
       die();
    }
}

But I want to add yandexbot and bingbot... How can i set?

  • FYI, if visitors won't see content that the search engine does, don't expect to stay listed for long. And if this is a way to protect content, bear in mind that people can change their user-agent. – user3757614 Oct 07 '15 at 18:48

1 Answers1

0

I have made an array for you. It has your favourite bots like googlebot, yahoo and yandex. You can also add any extra useragent if you want by placing it in the Crawlerlist array within single quotes seperated by commas.

You can Get list of All available UserAgents here: 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";

I hope this helps you. This is my first answer in Stack Overflow.

Łukasz
  • 8,555
  • 2
  • 28
  • 51