Create a Function to Check If User Is a Bot/Spider

If you ever need to check if a user/visitor is a bot or spider you can do so by creating this quick php function.
Check if User is a Robot or Spider
Is Bot Function
- /* Is Bot
- ------------------------------------------------------*/
function is_bot(){
$bot_list
= array("Ask Jeeves","Baiduspider","Butterfly","FAST","Feedfetcher-Google","Firefly","Gigabot","Googlebot","InfoSeek","Me.dium","Mediapartners-Google","NationalDirectory","Rankivabot","Scooter","Slurp","Sogou web spider","Spade","TECNOSEEK","TechnoratiSnoop","Teoma","TweetmemeBot","Twiceler","Twitturls","URL_Spider_SQL","WebAlta Crawler","WebBug","WebFindBot","ZyBorg","alexa","appie","crawler","froogle","girafabot","inktomi","looksmart","msnbot","rabaz","www.galaxy.com");
$user_agent
= $_SERVER["HTTP_USER_AGENT"];
foreach($bot_list as $bot){
if(strpos($user_agent,$bot)
!== false){
return true;
}
return false;
}
}
Simply run the function is_bot, and the user's $_SERVER["HTTP_USER_AGENT"] will be run through a list of commonly-known bots and return true if there's a match!