料青山看我应如是
经过一番谷歌搜索后,我找到了这段代码,它似乎可以正常工作(尽管没有检测到Unix)<?php $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){ // 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);