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

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
  1. /* Is Bot
  2. ------------------------------------------------------*/
  3. function is_bot(){
  4.  
  5. $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");
  6. $user_agent= $_SERVER["HTTP_USER_AGENT"];
  7.  
  8.  
  9. foreach($bot_list as $bot){
  10.  
  11. if(strpos($user_agent,$bot)!== false){
  12.  
  13. return true;
  14.  
  15. }
  16.  
  17.  
  18. return false;
  19.  
  20. }
  21.  
  22. }

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!

Tags

Add Comment

Leave a Comment or Reply
Fuel the conversation with your thoughts using the form below. Email is not made public.
× Processing...

Please Wait while your Comment is being Processed.

*
*
*

Comments 1 Total Responses