how to identify web crawlers of google/yahoo/msn by PHP?

前端 未结 8 1539
清酒与你
清酒与你 2020-12-29 17:51

AFAIK,

$_SERVER[\'REMOTE_HOST\'] should end up with \"google.com\" or \"yahoo.com\".

but is it the most ensuring method?

any other way out?

相关标签:
8条回答
  • 2020-12-29 18:12

    Google/Bing/Yahoo Crawlers IP Addresses -

    http://myip.ms/info/bots/Google_Bing_Yahoo_Facebook_etc_Bot_IP_Addresses.html

    0 讨论(0)
  • 2020-12-29 18:18

    I hacked something together, but you will have to look at $_SERVER['HTTP_USER_AGENT'] to see if they come from a search-engine domain.

    function is_crawlers() {
    
       $sites = 'Google|Yahoo|msnbot|'; // Add the rest of the search-engines 
    
       return (preg_match("/$sites/", $_SERVER['HTTP_USER_AGENT']) > 0) ? true : false;  
    
       }
    
    0 讨论(0)
提交回复
热议问题