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.
<?php function botDetect() { $bots_list=array( "Google"=>"Googlebot", "Yahoo"=>"Slurp", "Bing"=>"bingbot" /*You can add more bot here*/ ); $regexp='/'. implode("|", $bots_list).'/'; $ua=$_SERVER['HTTP_USER_AGENT']; if(preg_match($regexp, $ua,$matches)) { $bot= array_search($matches[0], $bots_list); return $bot; } else { return false; } } ?>
I was newbe about programming, your post is very helpful in determining the number of robots who visit our website. Thanks very much