-
-
Save mrLexx/13799e4fc0a928db38b17c005e362e47 to your computer and use it in GitHub Desktop.
Revisions
-
worka revised this gist
Oct 25, 2019 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,13 +3,18 @@ ```php function detectSearchBot($ip, $agent, &$hostname) { $hostname = $ip; // check HTTP_USER_AGENT what not to touch gethostbyaddr in vain if (preg_match('/(?:google|yandex)bot/iu', $agent)) { // success - return host, fail - return ip or false $hostname = gethostbyaddr($ip); // https://support.google.com/webmasters/answer/80553 if ($hostname !== false && $hostname != $ip) { // detect google and yandex search bots if (preg_match('/\.((?:google(?:bot)?|yandex)\.(?:com|ru))$/iu', $hostname)) { // success - return ip, fail - return hostname $ip = gethostbyname($hostname); if ($ip != $hostname) { -
worka revised this gist
Oct 25, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ### Detect google and yandex search bots (crawl, spider) ```php function detectSearchBot($ip, $agent, &$hostname) -
worka renamed this gist
Oct 24, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
worka revised this gist
Oct 24, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ### Detect google and yandex search bots ```php function detectSearchBot($ip, $agent, &$hostname) -
worka created this gist
Oct 24, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ ### detect google and yandex search bots ```php 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; } ```