I am creating a small script to collect web stats and do not want it to run when spiders or bots are crawling my site. At the moment I have lots of records in my database that are hits from spiders and bots and I am not interested in them. Is there a PHP function I can use to determine if the requester is a human or a spider/bot?
Try something like: For detecting if the visitor is a bot or not: <?php function is_bot(){ //array of bot names $bots = array("Googlebot", "alexa", "msnbot"); if(in_array($_SERVER['HTTP_USER_AGENT'], $bots)){ return true; } else { return false; } } ?> PHP: Usage: <?php if(is_bot() == false){ //the visitor is not a bot... } else { //the visitor is a bot... } ?> PHP: