1

Google Botのみに設定した場合; このコードでこの設定を行うことができます:

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

でも、yandexbot と bingbot を追加したいのですが... どうすれば設定できますか?

4

1 に答える 1

0

私はあなたのために配列を作りました。googlebot、yahoo、yandex などのお気に入りのボットがあります。必要に応じて、カンマで区切られた一重引用符内の Crawlerlist 配列にユーザー エージェントを配置することで、追加のユーザー エージェントを追加することもできます。

ここで利用可能なすべての 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 での最初の回答です。

于 2015-10-07T18:48:49.030 に答える