I want to only shown my web site to googlebot, yandex or bing. How can i set?

344 Views Asked by At

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?

1

There are 1 best solutions below

0
AudioBubble On

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.