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