当前位置:  开发笔记 > 编程语言 > 正文

从浏览器中检测确切的OS版本

如何解决《从浏览器中检测确切的OS版本》经验,为你挑选了3个好方法。

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

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



1> Can Berk Güd..:

简答:你做不到.

答案很长:

您所拥有的只是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(强悍)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; zh-CN)AppleWebKit/528.16(KHTML,与Gecko一样)Version/4.0 Safari/528.16

另一方面,Windows浏览器通常只报告操作系统版本而不报告特定包(专业版,商务版等):

Mozilla/5.0(Windows; U; Windows NT 5.1; en-US; rv:xxx)Gecko/20041107 Firefox/xx


@Roy:也许,但我不会赌它.

2> Reed Richard..:

经过一些谷歌搜索我发现这个代码,它似乎工作正常,(虽然没有检测到Unix)

 '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 systems
foreach($OSList as $CurrOS=>$Match)
{
// Find a match
if (eregi($Match, $_SERVER['HTTP_USER_AGENT']))
{
// We found the correct match
break;
}
}
// You are using ...
echo "You are using ".$CurrOS;
?>


小心:不推荐使用eregi!

3> 小智..:

//这会对你有所帮助

$uagent = $_SERVER['HTTP_USER_AGENT'] . "
"; 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)', 'Windows 8.1' => '(Windows NT 6.3)', 'Windows 10' => '(Windows NT 10.0)', '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);

推荐阅读
U友50081205_653
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有