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 }