how to detect search engine bots with php? Ask Question

how to detect search engine bots with php? Ask Question

How can one detect the search engine bots using php?

ベストアンサー1

I use the following code which seems to be working fine:

function _bot_detected() {

  return (
    isset($_SERVER['HTTP_USER_AGENT'])
    && preg_match('/bot|crawl|slurp|spider|mediapartners/i', $_SERVER['HTTP_USER_AGENT'])
  );
}

update 16-06-2017 https://support.google.com/webmasters/answer/1061943?hl=en

added mediapartners

おすすめ記事