zoukankan      html  css  js  c++  java
  • PHP获取用户操作系统信息

     1 function getOS() {
     2   // Create list of operating systems with operating system name as array key 
     3       $userAgent=$_SERVER["HTTP_USER_AGENT"];
     4     $oses = array (
     5         'iPhone' => '(iPhone)',
     6         'Windows 3.11' => 'Win16',
     7         'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)', // Use regular expressions as value to identify operating system
     8         'Windows 98' => '(Windows 98)|(Win98)',
     9         'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
    10         'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
    11         'Windows 2003' => '(Windows NT 5.2)',
    12         'Windows Vista' => '(Windows NT 6.0)|(Windows Vista)',
    13         'Windows 7' => '(Windows NT 6.1)|(Windows 7)',
    14         'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
    15         'Windows ME' => 'Windows ME',
    16         'Open BSD'=>'OpenBSD',
    17         'Sun OS'=>'SunOS',
    18         'Linux'=>'(Linux)|(X11)',
    19         'Safari' => '(Safari)',
    20         'Macintosh'=>'(Mac_PowerPC)|(Macintosh)',
    21         'QNX'=>'QNX',
    22         'BeOS'=>'BeOS',
    23         'OS/2'=>'OS/2',
    24         'Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)'
    25     );
    26 
    27     foreach($oses as $os=>$pattern){ // Loop through $oses array
    28     // Use regular expressions to check operating system type
    29         if(eregi($pattern, $userAgent)) { // Check if a value in $oses array matches current user agent.
    30             return $os; // Operating system was matched so return $oses key
    31         }
    32     }
    33     return 'Unknown'; // Cannot find operating system so return Unknown
    34 }
  • 相关阅读:
    1015. 德才论
    1014. 福尔摩斯的约会
    1013. 数素数
    1012. 数字分类
    1011. A+B和C
    1010. 一元多项式求导
    1009. 说反话
    1008. 数组元素循环右移问题
    1007. 素数对猜想
    1006. 换个格式输出整数
  • 原文地址:https://www.cnblogs.com/liusir/p/3166445.html
Copyright © 2011-2022 走看看