canadabeeau Posted December 14, 2009 Share Posted December 14, 2009 How in PHP or other language can I detect Operating system, ie Windows XP Home, Windows 7 Ultimate, Mac OS 10? Anyone know how? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 14, 2009 Share Posted December 14, 2009 You can determine the operating system using a client side language like Javascript using the navigator.appVersion string.. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 14, 2009 Author Share Posted December 14, 2009 That returns "Win32" I found this http://techpatterns.com/downloads/php_browser_detection.php but cant get it to work, I downloaded http://techpatterns.com/downloads/scripts/javascript_browser_detection.txt and made it browser.php but cant get it to work, ideas anyone? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 14, 2009 Share Posted December 14, 2009 How in PHP or other language can I detect Operating system, ie Windows XP Home, Windows 7 Ultimate, Mac OS 10? Anyone know how? Thanks in advance You can only find the OS using the client's UA (User Agent). Note this is sent by the client and may be blank, or spoofed. $OSList = array ( // Match user agent string with operating systems 'Windows 3.11' => '/Win16/i', 'Windows 95' => '/(Windows 95)|(Win95)|(Windows_95)/i', 'Windows 98' => '/(Windows 98)|(Win98)/i', 'Windows 2000' => '/(Windows NT 5.0)|(Windows 2000)/i', 'Windows XP' => '/(Windows NT 5.1)|(Windows XP)/i', 'Windows Server 2003' => '/(Windows NT 5.2)/i', 'Windows Vista' => '/(Windows NT 6.0)/i', 'Windows 7 ' => '/(Windows NT 7.0)/i', 'Windows NT 4.0' => '/(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)/i', 'Windows ME' => '/Windows ME/i', 'Open BSD ' => '/OpenBSD/i', 'Sun OS ' => '/SunOS/i', 'Linux' => '/(Linux)|(X11)/i', 'Mac OS' => '/(Mac_PowerPC)|(Macintosh)/i', 'QNX' => '/QNX/i', 'BeOS' => '/BeOS/i', 'Search Bot'=>'/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)/i' ); // Loop through the array of user agents and matching operating systems foreach($OSList as $CurrOS=>$Match) { // Find a match if (preg_match($Match, $_SERVER['HTTP_USER_AGENT'])) { // We found the correct match break; } } I rewrote an example I found to be more up to date for you.. This should work, and is the only possible method. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 14, 2009 Author Share Posted December 14, 2009 <?php $OSList = array ( // Match user agent string with operating systems 'Windows 3.11' => '/Win16/i', 'Windows 95' => '/(Windows 95)|(Win95)|(Windows_95)/i', 'Windows 98' => '/(Windows 98)|(Win98)/i', 'Windows 2000' => '/(Windows NT 5.0)|(Windows 2000)/i', 'Windows XP' => '/(Windows NT 5.1)|(Windows XP)/i', 'Windows Server 2003' => '/(Windows NT 5.2)/i', 'Windows Vista' => '/(Windows NT 6.0)/i', 'Windows 7 ' => '/(Windows NT 7.0)/i', 'Windows NT 4.0' => '/(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)/i', 'Windows ME' => '/Windows ME/i', 'Open BSD ' => '/OpenBSD/i', 'Sun OS ' => '/SunOS/i', 'Linux' => '/(Linux)|(X11)/i', 'Mac OS' => '/(Mac_PowerPC)|(Macintosh)/i', 'QNX' => '/QNX/i', 'BeOS' => '/BeOS/i', 'Search Bot'=>'/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)/i' ); // Loop through the array of user agents and matching operating systems foreach($OSList as $CurrOS=>$Match) { // Find a match if (preg_match($Match, $_SERVER['HTTP_USER_AGENT'])) { // We found the correct match break; } } ?> How do I get it to display (echo)?? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 14, 2009 Share Posted December 14, 2009 Just add one line: // Loop through the array of user agents and matching operating systems foreach($OSList as $CurrOS=>$Match) { // Find a match if (preg_match($Match, $_SERVER['HTTP_USER_AGENT'])) { // We found the correct match echo $CurrOS; break; } } You can also wrap it in a function, and return $CurrOS instead of echoing it so you can place it in a variable. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 14, 2009 Author Share Posted December 14, 2009 Okay my genuine Windows 7 ultimate according to your script is Windows NT 4.0. HELP???? Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 14, 2009 Author Share Posted December 14, 2009 Why cant I get this one to work, it detects correctly http://techpatterns.com/downloads/php_browser_detection.php When I download it I cant get it to work, any one have an idea? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 14, 2009 Share Posted December 14, 2009 Why cant I get this one to work, it detects correctly http://techpatterns.com/downloads/php_browser_detection.php When I download it I cant get it to work, any one have an idea? What doesn't work of it, what errors does it give you? It seems to use the EXACT same method to pull out the OS. By the way, what is your user agent string? If it contains 'win7' instead of NT 7.0, you can simply add /win7/i, to the array to match it. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 14, 2009 Author Share Posted December 14, 2009 This is now resolved, got a different script to work. Thanks goes to oni-kun and Buddski who seems to be coming to my aid with all my posts so special thanks to you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.