看看http://ellislab.com/codeigniter/user-guide/libraries/user_agent.html
根据Detect exact OS version from browser
简答:你不能。
长答案:
您所拥有的只是 HTTP User-Agent 标头中的信息,通常包含操作系统名称和版本。
通常,在 Mac OS 和 Linux 上运行的浏览器会发送足够的信息来识别确切的操作系统。例如,这是我的 User-Agent 标头:
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.7) Gecko/2009030423 Ubuntu/8.10 (intrepid) Firefox/3.0.7
您可以看到我正在运行 Ubuntu 8.10 Intrepid Ibex。
以下是 Firefox 和 Safari 4 Beta 在我的 MacBook Pro 上的报告:
Mozilla/5.0(Macintosh;U;Intel Mac OS X 10.5;en-US;rv:1.9.0.7)Gecko/2009021906 Firefox/3.0.7
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16
另一方面,Windows 浏览器通常只报告操作系统版本而不是特定的包(Pro、Business 等):
Mozilla/5.0(Windows;U;Windows NT 5.1;en-US;rv:x.x.x)Gecko/20041107 Firefox/x.x
// 这对你有帮助
$uagent = $_SERVER['HTTP_USER_AGENT'] . "<br/>";
function os_info($uagent)
{
// the order of this array is important
global $uagent;
$oses = array(
'Win311' => 'Win16',
'Win95' => '(Windows 95)|(Win95)|(Windows_95)',
'WinME' => '(Windows 98)|(Win 9x 4.90)|(Windows ME)',
'Win98' => '(Windows 98)|(Win98)',
'Win2000' => '(Windows NT 5.0)|(Windows 2000)',
'WinXP' => '(Windows NT 5.1)|(Windows XP)',
'WinServer2003' => '(Windows NT 5.2)',
'WinVista' => '(Windows NT 6.0)',
'Windows 7' => '(Windows NT 6.1)',
'Windows 8' => '(Windows NT 6.2)',
'WinNT' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
'OpenBSD' => 'OpenBSD',
'SunOS' => 'SunOS',
'Ubuntu' => 'Ubuntu',
'Android' => 'Android',
'Linux' => '(Linux)|(X11)',
'iPhone' => 'iPhone',
'iPad' => 'iPad',
'MacOS' => '(Mac_PowerPC)|(Macintosh)',
'QNX' => 'QNX',
'BeOS' => 'BeOS',
'OS2' => 'OS/2',
'SearchBot' => '(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)'
);
$uagent = strtolower($uagent ? $uagent : $_SERVER['HTTP_USER_AGENT']);
foreach ($oses as $os => $pattern)
if (preg_match('/' . $pattern . '/i', $uagent))
return $os;
return 'Unknown';
}
echo os_info($uagent);