This snippet is displaying short info of user agent like iPhone, Android, HTC, Nokia...
I didn't intend to scrap all possible ua, just most commonly used.
Any feedback is welcome.
Usage Example:
I didn't intend to scrap all possible ua, just most commonly used.
Any feedback is welcome.
PHP Code:
function shortua() {
/* SNIPPET BY ARNAGE http://wapforum.rs * DOWNLOAD AT http://coding-talk.com */
$userbrowser = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$userbrowser = isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) ? $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'] : $userbrowser;
$userbrowser = isset($_SERVER['HTTP_X_ORIGINAL_USER_AGENT']) ? $_SERVER['HTTP_X_ORIGINAL_USER_AGENT'] : $userbrowser;
$userbrowser = isset($_SERVER['HTTP_X_DEVICE_USER_AGENT']) ? $_SERVER['HTTP_X_DEVICE_USER_AGENT'] : $userbrowser;
$userbrowser = isset($_SERVER['HTTP_X_MOBILE_UA']) ? $_SERVER['HTTP_X_MOBILE_UA'] : $userbrowser;
$userbrowser = isset($_SERVER['HTTP_X_BOLT_PHONE_UA']) ? $_SERVER['HTTP_X_BOLT_PHONE_UA'] : $userbrowser;
$useragent = !empty($userbrowser) ? htmlentities($userbrowser, ENT_QUOTES, 'UTF-8') : 'Browser';
if (strpos($useragent, '/') !== false) {
$agent = explode('/', $useragent);
if (stripos($useragent, 'Mini') !== false) {
$short = $agent[0].'Mini';
}
elseif (stripos($useragent, 'Nokia') !== false) {
if (strcmp($agent[0], 'Mozilla') == 0)
$short = 'Nokia';
else
$short = $agent[0];
}
elseif (stripos($useragent, 'iPhone') !== false) {
$short = 'iPhone';
}
elseif (stripos($useragent, 'MSIE') !== false) {
if (stripos($useragent, 'HTC') !== false)
$short = 'HTC';
elseif (stripos($useragent, 'IEMobile') !== false)
$short = 'WindowsMobile';
else
$short = 'PC';
}
elseif (stripos($useragent, 'Android') !== false) {
if (stripos($useragent, 'HTC') !== false)
$short = 'HTC Android';
else
$short = 'Android';
}
elseif (stripos($useragent, 'BlackBerry') !== false) {
$short = 'BlackBerry';
}
elseif (stripos($useragent, 'lg-') !== false) {
$short = 'LG';
}
elseif (stripos($useragent, 'sie-') !== false) {
$short = 'Siemens';
}
elseif (stripos($useragent, 'Firefox') !== false) {
$short = 'PC';
}
elseif (stripos($useragent, 'Chrome') !== false) {
$short = 'PC';
}
else {
$short = $agent[0];
}
} else {
$short = mb_strlen($useragent, 'UTF-8') > 10 ? mb_substr($useragent, 0, 10, 'UTF-8') : $useragent;
}
return $short;
}
PHP Code:
echo '<a href="http://somead.tld/?ref=00001">Free '.shortua().' Downloads!</a>';
Comment