Determining client operating system and browser : HTTP_USER_AGENT « HTML « PHP






Determining client operating system and browser

 
<?
function browser_info ($agent) {
     if (ereg( 'MSIE ([09].[09]{1,2})', $agent, $version)) :
          $browse_type = "IE";
          $browse_version = $version[1];
     elseif (ereg( 'Opera ([09].[09]{1,2})', $agent, $version)) :
          $browse_type = "Opera";
          $browse_version = $version[1];
     elseif (ereg( 'Mozilla/([09].[09]{1,2})', $agent, $version)) :
          $browse_type = "Netscape";
          $browse_version = $version[1];
     else :
          $browse_type = "Unknown";
          $browse_version = "Unknown";
     endif;
     return array($browse_type, $browse_version);

}

function operatingsystem_info($agent) {
     if ( strstr ($agent, 'Win') ) :
          $operatingsystem = "Windows";
     elseif ( strstr($agent, 'Linux') ) :
          $operatingsystem = "Linux";
     elseif ( strstr ($agent, 'Unix') ) :
          $operatingsystem = "Unix";
     elseif ( strstr ($agent,'Mac') ) :
          $operatingsystem = "Macintosh";
     else :
          $operatingsystem = "Unknown";
     endif;
     return $operatingsystem;

}
list ($browse_type, $browse_version) = browser_info ($HTTP_USER_AGENT);
$operating_sys = operatingsystem_info ($HTTP_USER_AGENT);

print "Browser Type: $browse_type <br>";
print "Browser Version: $browse_version <br>";
print "Operating System: $operating_sys <br>";

?>
  
  








Related examples in the same category

1.Browser Detection
2.Browser content
3.Get Browser and Platform
4.Welcome Page with HTTP_USER_AGENT
5.Reporting the User Agent and Referrer