How to detect Browser User-Agent

Do you want to know beforehand what browser is being used by clients visiting your site? With a little PHP programming, you can add this on your existing script. You can then use this on browser based redirections, or simply to show off browsers either in posts or in email logs.

function getua() {
if (isset ($_SERVER[‘HTTP_X_OPERAMINI_PHONE_UA’])) {
$uas = explode(‘/’, $_SERVER[‘HTTP_X_OPERAMINI_PHONE_UA’]);
$ua = $uas[0];
}
else
if (isset ($_SERVER[‘HTTP_X_ORIGINAL_USER_AGENT’])) {
$uas = explode(‘/’, $_SERVER[‘HTTP_X_ORIGINAL_USER_AGENT’]);
$ua = $uas[0];
}
else
if (isset ($_SERVER[‘HTTP_X_DEVICE_USER_AGENT’])) {


$uas = explode(‘/’, $_SERVER[‘HTTP_X_DEVICE_USER_AGENT’]);
$ua = $uas[0];
}
else
if (isset ($_SERVER[‘HTTP_X_BOLT_PHONE_UA’])) {
$uas = explode(‘/’, $_SERVER[‘HTTP_X_BOLT_PHONE_UA’]);
$ua = $uas[0];
}
else
if (isset ($_SERVER[‘HTTP_X_MOBILE_UA’])) {
$uas = explode(‘/’, $_SERVER[‘HTTP_X_MOBILE_UA’]);
$ua = $uas[0];
}
else {
$uas = explode(‘/’, $_SERVER[‘HTTP_USER_AGENT’]);
$ua = $uas[0];
}
return $ua;
}

Leave a Reply

Your email address will not be published. Required fields are marked *