jfb_get_browser

Simple browser detection, for logging (from http://php.net/manual/en/function.get-browser.php) (Doesn't require browscap.ini to be installed on the server, like standard PHP get_browser()).

Description

jfb_get_browser(); 

Usage

  1. if ( !function_exists( 'jfb_get_browser' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'wp-fb-autoconnect/__inc_opts.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = jfb_get_browser(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/__inc_opts.php  
  1. function jfb_get_browser() 
  2. $u_agent = $_SERVER['HTTP_USER_AGENT']; 
  3. $bname = 'Unknown'; 
  4. $shortname = 'Unknown'; 
  5. $platform = 'Unknown'; 
  6. $version= ""; 
  7.  
  8. //Get platform 
  9. if (preg_match('/android/i', $u_agent)) $platform = 'Android'; //Must come BEFORE 'linux' 
  10. elseif (preg_match('/linux/i', $u_agent)) $platform = 'Linux'; 
  11. elseif (preg_match('/iphone/i', $u_agent)) $platform = 'iPhone'; //Must come BEFORE 'mac' 
  12. elseif (preg_match('/ipad/i', $u_agent)) $platform = 'iPad'; //Must come BEFORE 'mac' 
  13. elseif (preg_match('/macintosh|mac os x/i', $u_agent) && !preg_match('/iPhone/i', $u_agent)) $platform = 'Mac'; 
  14. elseif (preg_match('/windows|win32/i', $u_agent)) $platform = 'Windows'; 
  15.  
  16. //Get name and shortname 
  17. if(preg_match('/MSIE/i', $u_agent) && !preg_match('/Opera/i', $u_agent)) {$bname = 'Internet Explorer'; $shortname = "MSIE"; } 
  18. elseif(preg_match('/Firefox/i', $u_agent)) {$bname = 'Mozilla Firefox'; $shortname = "Firefox"; } 
  19. elseif(preg_match('/Chrome/i', $u_agent)) {$bname = 'Google Chrome'; $shortname = "Chrome"; } 
  20. elseif(preg_match('/Safari/i', $u_agent)) {$bname = 'Apple Safari'; $shortname = "Safari"; } 
  21. elseif(preg_match('/Opera/i', $u_agent)) {$bname = 'Opera'; $shortname = "Opera"; } 
  22. elseif(preg_match('/Netscape/i', $u_agent)) {$bname = 'Netscape'; $shortname = "Netscape"; } 
  23.  
  24. //Get version 
  25. $known = array('Version', $shortname, 'other'); 
  26. $pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#'; 
  27. @preg_match_all($pattern, $u_agent, $matches); 
  28. $i = count($matches['browser']); 
  29. if ($i != 1 && strripos($u_agent, "Version") < strripos($u_agent, $shortname))$version= $matches['version'][0];  
  30. else if($i != 1) $version= $matches['version'][1]; 
  31. else $version= $matches['version'][0]; 
  32. if ($version==null || $version=="") {$version="?";} 
  33.  
  34. //Done - return! 
  35. return array('name'=>$bname, 'shortname'=>$shortname, 'version'=>$version, 'platform'=>$platform ); 
  36. }