Advertisement
Sk8erPeter

Sk8erPeter - function is_real_agent()

May 12th, 2011
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. /**
  2.  * is_real_agent() - Check if user agent given as a parameter is a search robot or a "real" visitor (list is absolutely incomplete :-) )
  3.  * Original source (code modified below): http://neo22s.com/function-to-check-if-visitor-is-a-bot/
  4.  * @param string $HTTP_USER_AGENT - böngésző ($_SERVER['HTTP_USER_AGENT'])
  5.  * @return bool is_real_agent - is it a "real" visitor?
  6.  */
  7. function is_real_agent( $HTTP_USER_AGENT ){
  8.     $unreal_agent_list = array(
  9.         "W3C_Validator", // not a search robot, but isn't a "real" visitor
  10.         "blahblahblahblahblah" // modify as you wish
  11.     );
  12.     $botlist = array(
  13.         "Googlebot", "Feedfetcher-Google", "Mediapartners-Google",
  14.         "Teoma", "alexa", "froogle", "Gigabot", "inktomi",
  15.         "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
  16.         "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
  17.         "crawler", "www.galaxy.com", "Scooter", "Slurp",
  18.         "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
  19.         "Baiduspider", "TechnoratiSnoop", "Rankivabot",
  20.         "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
  21.         "Butterfly","Twitturls", "Me.dium", "Twiceler"
  22.     );
  23.  
  24.     foreach($unreal_agent_list as $unreal_agent){
  25.         if(stripos($HTTP_USER_AGENT, $unreal_agent)!==false){
  26.             return false;    // Is not real
  27.         }
  28.     }
  29.    
  30.     foreach($botlist as $bot){
  31.         if(stripos($HTTP_USER_AGENT, $bot)!==false){
  32.             return false;    // Is a bot
  33.         }
  34.     }
  35.  
  36.     return true;    // Not a bot
  37. }
  38.  
  39.  
  40. /// ............
  41. // using the function below:
  42.  
  43. // if user agent header is set, we can check if it's a search robot or a real (e.g. human :D) visitor
  44. if( !empty($_SERVER['HTTP_USER_AGENT']) ) {
  45.     $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
  46.     if(false == is_real_agent($HTTP_USER_AGENT)){
  47.         $real_visitor = 'false';
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement