从浏览器检测确切的操作系统版本

我想知道是否有一种方法可以使用PHP / JS / ASP从浏览器中检测确切的操作系统版本?

我知道我可以检测操作系统的类型(Windows XP,Windows Vista,OS X等),但是我需要检测确切的版本:Vista Business,Vista Ultimate,Windows XP Home,Windows XP Pro等。


慕尼黑8549860
浏览 959回答 3
3回答

翻阅古今

简短的回答:不能。长答案:您所拥有的只是HTTP User-Agent标头中的信息,该标头通常包含操作系统名称和版本。通常,在Mac OS和Linux上运行的浏览器会发送足够的信息以标识确切的OS。例如,这是我的User-Agent标头:Mozilla / 5.0(X11; U; Linux x86_64; zh-CN; rv:1.9.0.7)Gecko / 2009030423 Ubuntu / 8.10(intrepid)Firefox / 3.0.7您可以看到我正在运行Ubuntu 8.10 Intrepid Ibex。这是MacBook Pro上Firefox和Safari 4 Beta的报告:Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.7)Gecko / 2009021906 Firefox / 3.0.7Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10_5_6; zh-cn)AppleWebKit / 528.16(KHTML,如Gecko)版本/4.0 Safari / 528.16另一方面,Windows浏览器通常仅报告操作系统版本,而不报告特定的程序包(Pro,Business等):Mozilla / 5.0(Wi

料青山看我应如是

经过一番谷歌搜索后,我找到了这段代码,它似乎可以正常工作(尽管没有检测到Unix)<?php&nbsp;$OSList = array(// Match user agent string with operating systems'Windows 3.11' => 'Win16','Windows 95' => '(Windows 95)|(Win95)|(Windows_95)','Windows 98' => '(Windows 98)|(Win98)','Windows 2000' => '(Windows NT 5.0)|(Windows 2000)','Windows XP' => '(Windows NT 5.1)|(Windows XP)','Windows Server 2003' => '(Windows NT 5.2)','Windows Vista' => '(Windows NT 6.0)','Windows 7' => '(Windows NT 7.0)','Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)','Windows ME' => 'Windows ME','Open BSD' => 'OpenBSD','Sun OS' => 'SunOS','Linux' => '(Linux)|(X11)','Mac OS' => '(Mac_PowerPC)|(Macintosh)','QNX' => 'QNX','BeOS' => 'BeOS','OS/2' => 'OS/2','Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)');// Loop through the array of user agents and matching operating systemsforeach($OSList as $CurrOS=>$Match){// Find a matchif (eregi($Match, $_SERVER['HTTP_USER_AGENT'])){// We found the correct matchbreak;}}// You are using ...echo "You are using ".$CurrOS;?>

智慧大石

//这将为您提供帮助$uagent = $_SERVER['HTTP_USER_AGENT'] . "<br/>";function os_info($uagent){&nbsp; &nbsp; // the order of this array is important&nbsp; &nbsp; global $uagent;&nbsp; &nbsp; $oses&nbsp; &nbsp;= array(&nbsp; &nbsp; &nbsp; &nbsp; 'Win311' => 'Win16',&nbsp; &nbsp; &nbsp; &nbsp; 'Win95' => '(Windows 95)|(Win95)|(Windows_95)',&nbsp; &nbsp; &nbsp; &nbsp; 'WinME' => '(Windows 98)|(Win 9x 4.90)|(Windows ME)',&nbsp; &nbsp; &nbsp; &nbsp; 'Win98' => '(Windows 98)|(Win98)',&nbsp; &nbsp; &nbsp; &nbsp; 'Win2000' => '(Windows NT 5.0)|(Windows 2000)',&nbsp; &nbsp; &nbsp; &nbsp; 'WinXP' => '(Windows NT 5.1)|(Windows XP)',&nbsp; &nbsp; &nbsp; &nbsp; 'WinServer2003' => '(Windows NT 5.2)',&nbsp; &nbsp; &nbsp; &nbsp; 'WinVista' => '(Windows NT 6.0)',&nbsp; &nbsp; &nbsp; &nbsp; 'Windows 7' => '(Windows NT 6.1)',&nbsp; &nbsp; &nbsp; &nbsp; 'Windows 8' => '(Windows NT 6.2)',&nbsp; &nbsp; &nbsp; &nbsp; 'Windows 8.1' => '(Windows NT 6.3)',&nbsp; &nbsp; &nbsp; &nbsp; 'Windows 10' => '(Windows NT 10.0)',&nbsp; &nbsp; &nbsp; &nbsp; 'WinNT' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',&nbsp; &nbsp; &nbsp; &nbsp; 'OpenBSD' => 'OpenBSD',&nbsp; &nbsp; &nbsp; &nbsp; 'SunOS' => 'SunOS',&nbsp; &nbsp; &nbsp; &nbsp; 'Ubuntu' => 'Ubuntu',&nbsp; &nbsp; &nbsp; &nbsp; 'Android' => 'Android',&nbsp; &nbsp; &nbsp; &nbsp; 'Linux' => '(Linux)|(X11)',&nbsp; &nbsp; &nbsp; &nbsp; 'iPhone' => 'iPhone',&nbsp; &nbsp; &nbsp; &nbsp; 'iPad' => 'iPad',&nbsp; &nbsp; &nbsp; &nbsp; 'MacOS' => '(Mac_PowerPC)|(Macintosh)',&nbsp; &nbsp; &nbsp; &nbsp; 'QNX' => 'QNX',&nbsp; &nbsp; &nbsp; &nbsp; 'BeOS' => 'BeOS',&nbsp; &nbsp; &nbsp; &nbsp; 'OS2' => 'OS/2',&nbsp; &nbsp; &nbsp; &nbsp; 'SearchBot' => '(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)'&nbsp; &nbsp; );&nbsp; &nbsp; $uagent = strtolower($uagent ? $uagent : $_SERVER['HTTP_USER_AGENT']);&nbsp; &nbsp; foreach ($oses as $os => $pattern)&nbsp; &nbsp; &nbsp; &nbsp; if (preg_match('/' . $pattern . '/i', $uagent))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return $os;&nbsp; &nbsp; return 'Unknown';}echo os_info($uagent);
打开App,查看更多内容
随时随地看视频慕课网APP