<?php
function getBrowser($useragent) {
if (strpos($useragent, 'MSIE') !== FALSE && strpos($useragent, 'Opera') === FALSE && strpos($useragent, 'Netscape') === FALSE) {
if (preg_match("/Blazer\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $matches)) {
return 'Blazer ' . $matches[1];
}
if (preg_match("/MSIE ([0-9]{1,2}\.[0-9]{1,2})/", $useragent, $matches)) {
return 'Internet Explorer ' . $matches[1];
}
}
elseif (strpos($useragent, 'IEMobile') !== FALSE) {
if (preg_match("/IEMobile\/([0-9]{1,2}\.[0-9]{1,2})/", $useragent, $matches)) {
return 'Internet Explorer Mobile ' . $matches[1];
}
}
elseif (strpos($useragent, 'Gecko')) {
if (preg_match("/Firefox\/([0-9]{1,2}\.[0-9]{1,2}(\.[0-9]{1,2})?)/", $useragent, $matches)) {
return 'Mozilla Firefox ' . $matches[1];
}
if (preg_match("/Netscape\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $matches)) {
return 'Netscape ' . $matches[1];
}
if (preg_match("/Chrome\/([^\s]+)/", $useragent, $matches)) {
return 'Google Chrome ' . $matches[1];
}
if (preg_match("/Safari\/([0-9]{2,3}(\.[0-9])?)/", $useragent, $matches)) {
return 'Safari ' . $matches[1];
}
if (preg_match("/Galeon\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $matches)) {
return 'Galeon ' . $matches[1];
}
if (preg_match("/Konqueror\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $matches)) {
return 'Konqueror ' . $matches[1];
}
if (preg_match("/Fennec\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $matches)) {
return 'Fennec' . $matches[1];
}
if (preg_match("/Maemo\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $matches)) {
return 'Maemo' . $matches[1];
}
return 'Gecko based';
}
elseif (strpos($useragent, 'Opera') !== FALSE) {
if (preg_match("/Opera[\/ ]([0-9]{1}\.[0-9]{1}([0-9])?)/", $useragent, $matches)) {
return 'Opera ' . $matches[1];
}
}
elseif (strpos($useragent, 'Lynx') !== FALSE) {
if (preg_match("/Lynx\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $matches)) {
return 'Lynx ' . $matches[1];
}
}
elseif (strpos($useragent, 'Netscape') !== FALSE) {
if (preg_match("/Netscape\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $matches)) {
return 'Netscape ' . $matches[1];
}
}
else {
return 'unknown';
}
}
?>
<?php echo getBrowser($_SERVER["HTTP_USER_AGENT"]); ?>