Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function detectSearchBot($ip, &$hostname)
- {
- // success - return host
- // fail - return ip or false
- $hostname = gethostbyaddr($ip);
- // $hostname = '93-158-166-6.spider.yandex.com';
- // $hostname = '93-158-166-6.spider.yandex.ru';
- // $hostname = '93-158-166-6.spider.yan3dex.ru';
- // $hostname = 'crawl-66-249-79-95.googlebot.com';
- // $hostname = 'crawl-66-249-79-95.google.com';
- // https://support.google.com/webmasters/answer/80553
- if ($hostname !== false && $hostname != $ip) {
- // detect google and yandex bots
- $is_match = preg_match('/\.((?:google(?:bot)?|yandex)\.(?:com|ru))$/iu', $hostname);
- if ($is_match) {
- // success - return ip
- // fail - return hostname
- $ip = gethostbyname($hostname);
- if ($ip != $hostname) {
- return true;
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement