how to detect search engine bots with php?

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

Leave a Comment