Search code examples
phpipweb-crawlerreferer

Identify visit from robot


In my site, whenever there is a visit I send a cookie and then I save datas in db (data, ip, referer, platform). The cookie is used for avoid of recording the same user visit. My question is simple: how can I identify visit from robot? Is it possible?


Solution

  • read User Agent

    if( preg_match('/robot|spider|crawler|curl|^$/i', $_SERVER['HTTP_USER_AGENT'])) )
    { 
        echo 'Is bot or spider or crawler or curl or not human';
    }
    else
    {
        echo 'Is human';
    }
    

    You can find a list of about 300 common user-agents given by bots here: http://www.robotstxt.org/db.html