This article is an example of the PHP implementation to determine whether access routing is a search engine robot method. Share to everyone for your reference. The specific analysis is as follows:
Many times we need to identify the site visitors, for real users and search engines for different actions to achieve, then first need to judge whether the search engine.
Php method is very simple to judge, through the filter $_server[' http_user_agent ' parameters can be identified, the following is an excerpt from the source of the relevant source code:
Private Function Getrobot ()
{
if (empty ($_server[' http_user_agent '))
{return
false;
}
$searchEngineBot = Array (
' Googlebot ' => ' Google ', '
mediapartners-google ' => ' Google ',
' Baiduspider ' => ' Baidu,
' msnbot ' => ' MSN ', ' Yodaobot ' => ' Yodao '
, ' Youdaobot ' => ' Yodao '
' Yahoo! slurp ' => ' Yahoo ',
' Yahoo! slurp ' => ' Yahoo ',
' iaskspider
' => ' iask ', ' Sogou Web spider ' => ' Sogou ',
' Sogou push spider ' => ' Sogou ',
' sosospider ' => ' Soso ', ' spider '
= > ' Other ',
' crawler ' => ' other ',
);
$spider = Strtolower ($_server[' http_user_agent '));
foreach ($searchEngineBot as $key => $value)
{
if (Strpos ($spider, $key)!== false)
{return
$ value;
}
}
return false;
}
Public Function Isrobot ()
{
if ($this->getrobot ()!==false)
{return
true;
}
return false;
}
I hope this article will help you with your PHP program design.