Detect mobile os:
usage:PHP Code:
function detect_os ($ua) {
if (preg_match('#PalmOS#i', $ua)) {
$os_name = "Palm OS";
$os_code = "palm";
} elseif (preg_match('#Windows CE#i', $ua)) {
$os_name = "Windows CE";
$os_code = "windows";
} elseif (preg_match('#QtEmbedded#i', $ua)) {
$os_name = "Qtopia";
$os_code = "linux";
} elseif (preg_match('#Zaurus#i', $ua)) {
$os_name = "Linux";
$os_code = "linux";
} elseif (preg_match('#Symbian#i', $ua)) {
$os_name = "Symbian OS";
$os_code = "symbian";
}
if (preg_match('#PalmOS/sony/model#i', $ua)) {
$pda_name = "Sony Clie";
$pda_code = "sony";
} elseif (preg_match('#Zaurus ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$pda_name = "Sharp Zaurus " . $matches[1];
$pda_code = "zaurus";
$pda_ver = $matches[1];
} elseif (preg_match('#Series ([0-9]+)#i', $ua, $matches)) {
$pda_name = "Series";
$pda_code = "nokia";
$pda_ver = $matches[1];
} elseif (preg_match('#Nokia ([0-9]+)#i', $ua, $matches)) {
$pda_name = "Nokia";
$pda_code = "nokia";
$pda_ver = $matches[1];
} elseif (preg_match('#SIE-([a-zA-Z0-9]+)#i', $ua, $matches)) {
$pda_name = "Siemens";
$pda_code = "siemens";
$pda_ver = $matches[1];
} elseif (preg_match('#dopod([a-zA-Z0-9]+)#i', $ua, $matches)) {
$pda_name = "Dopod";
$pda_code = "dopod";
$pda_ver = $matches[1];
} elseif (preg_match('#o2 xda ([a-zA-Z0-9 ]+);#i', $ua, $matches)) {
$pda_name = "O2 XDA";
$pda_code = "o2";
$pda_ver = $matches[1];
} elseif (preg_match('#SEC-([a-zA-Z0-9]+)#i', $ua, $matches)) {
$pda_name = "Samsung";
$pda_code = "samsung";
$pda_ver = $matches[1];
} elseif (preg_match('#SonyEricsson ?([a-zA-Z0-9]+)#i', $ua, $matches)) {
$pda_name = "SonyEricsson";
$pda_code = "sonyericsson";
$pda_ver = $matches[1];
} elseif (preg_match('#Wii#i', $ua, $matches)) {
$pda_name = "Nintendo Wii";
$pda_code = "wii";
}
return array($os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver);
}
PHP Code:
$info=detect_os ($_SERVER['HTTP_USER_AGENT']);
echo 'OS name: '.$info[0].'
';
echo 'OS code: '.$info[1].'
';
echo 'OS version: '.$info[2].'
';
echo 'Brand: '.$info[3].'
'; //echo 'Phone code: '.$info[4].' ';
echo 'Model: '.$info[5].' ;
Tuesday, August 3, 2010
Detect mobile os
Labels:
Detect mobile os
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment