function detectSearchBot($ip, $agent, &$hostname)
{
// check HTTP_USER_AGENT not to pull gethostbyaddr in vain
if (preg_match('/(?:google|yandex)bot/iu', $agent)) {
$hostname = gethostbyaddr($ip);
if ($hostname !== false && $hostname != $ip) {
// detect google and yandex search bots
if (preg_match('/\.((?:google(?:bot)?|yandex)\.(?:com|ru))$/iu', $hostname)) {
$ip = gethostbyname($hostname);
if ($ip != $hostname) {
return true;
}
}
}
}
return false;
}-
-
Save mrLexx/13799e4fc0a928db38b17c005e362e47 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment