PHP function to detect spider bots

This php function helps to determine whether page is accessed by spider bot or not. If page is accessed by any of the bot listed in $bots_list array then function will return bot name otherwise it will return false. I have added only top 3 spider bots in list but you can expend it.

Usage examples:

  • Get email notification when your site is crawled by bots.
  • Save bots access information in database and generate custom stats.
  • Use to create special page for spider bots.
function botDetect()
/*You can add more bot here*/
$regexp='/'.  implode("|", $bots_list).'/';
if(preg_match($regexp, $ua,$matches))
$bot=  array_search($matches[0], $bots_list);
return $bot;
return false;

Liked It? Get Free updates in your Email

Delivered by feedburner

One thought on “PHP function to detect spider bots

  1. charger laptop

    I was newbe about programming, your post is very helpful in determining the number of robots who visit our website. Thanks very much


Leave a Reply

Your email address will not be published. Required fields are marked *