Detect the exact version of the OS from the browser

I was wondering if there is a way to determine the exact version of the operating system from my browser using PHP / JS / ASP?

I know that I can determine the type of OS (Windows XP, Windows Vista, OS X, etc.), but I need to determine the exact version: Vista Business, Vista Ultimate, Windows XP Home, Windows XP Pro, etc.

+18
javascript browser php
Mar 15 '09 at 15:19
source share
11 answers

Short answer: You cannot.

Long answer:

All you have is the information in the User-Agent HTTP header, which usually contains the name and version of the OS.

Typically, browsers running on Mac OS and Linux send enough information to determine the exact OS. For example, here is the User-Agent header:

Mozilla / 5.0 (X11; U; Linux x86_64; en-US; rv: 1.9.0.7) Gecko / 2009030423 Ubuntu / 8.10 (intrepid) Firefox / 3.0.7

You can see that I am running Ubuntu 8.10 Intrepid Ibex.

Here's the report from Firefox and Safari 4 Beta on my 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; ru-us) AppleWebKit / 528.16 (KHTML, e.g. Gecko) Version /4.0 Safari / 528.16

Windows browsers, on the other hand, usually only report the OS version, not a specific package (Pro, Business, etc.):

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

+25
Mar 15 '09 at 15:24
source share

After some googling, I found this code and it seems to work fine (doesn't detect 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 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; ?> 
+17
Apr 26 '09 at 20:03
source share

// this will help you

 $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); 
+14
Jul 01 2018-12-12T00:
source share

In classic ASP and ASP.NET use

 Request.ServerVariables("HTTP_USER_AGENT") 

This works best since it is not interpreted by the code, it is executed on the server.

+2
Mar 15 '09 at 16:27
source share

I do not think that you can distinguish between different versions of Vista, but you should get the OS from the navigator object platform property. You may have to disassemble it, or differentiate based on its contents.

 <script type="text/javascript"> alert( navigator.platform ); </script> 

See www.w3schools.com tutorials for an example shows how to get all the properties of a navigator.

EDIT

To get the exact version, you can create an ActiveX control (for Windows only) or a Java applet and use the java.lang.System object to view the current system properties. You can get enough information from the browser for non-Windows systems and use the control only for Windows systems. I have not tried this, so you will need to experiment to make sure this works. I must believe that the Microsoft ActiveX control for Microsoft Update is able to detect the exact version of the system and the installed software for its operation.

+1
Mar 15 '09 at 15:28
source share

You really should try to avoid doing something like this if it is absolutely necessary for the functionality of the web application.

Keep in mind that:

Not all requests may come from a windows client.

Not all requests may come from a client that supports JavaScript.

The user request header may not be present in the request.

What is in the header of the user agent may be skipped.

A well-designed web application should provide full content and functionality no matter what the request agent's header is, or if the client supports javascript or any other client extension.

+1
Mar 15 '09 at 15:54
source share

As others have said, no, not reliably.

That is why, for example, jquery switched to the browser capabilities system (due to the lack of a better word) instead of the browning system for its functionality.

+1
Mar 15 '09 at 16:06
source share

I created a jquery function that does this. Thus, we can track the entire OS using the navigator .

Hope someone gets help from this:

 function find_os_version() { var ua = navigator.userAgent.toLowerCase(); if (ua.indexOf("windows nt 5.0") != -1) { return 'win2k'; } if (ua.indexOf("windows nt 5.1") != -1) { return 'winXP'; } if (ua.indexOf("windows nt 6.0") != -1) { return 'winVista'; } if (ua.indexOf("windows nt 6.1") != -1) { return 'win7'; } if (ua.indexOf("windows nt 6.2") != -1) { return 'win8'; } } 
+1
Mar 13 '13 at 7:35
source share

This may be the easiest way:

Download the library from http://mobiledetect.net

Put Mobile_Detect.php in the "library" if you use CI or just enable it.

Use this code in PHP

 $detect = new Mobile_Detect(); // Get the version() of components. $detect->version('iPad'); // 4.3 (float) $detect->version('iPhone') // 3.1 (float) $detect->version('Android'); // 2.1 (float) $detect->version('Opera Mini'); // 5.0 (float) 

Find documentation at http://dwij.co.in/mobile-os-detection-in-php-codeigniter

+1
Dec 11 '13 at
source share

in CodeIgniter you can find a library called user_agent. This will give you everything you really need. If you are not using CI, you can still β€œextract” the code for your structure. Hope this helps. http://codeigniter.com/user_guide/libraries/user_agent.html

0
Jan 25 2018-12-12T00:
source share

Although the question is very old, but I just answer it:

just try:

$this->agent->platform()

this will give you an output like: Linux, Windows, OS X, etc.

for more information:

http://ellislab.com/codeigniter/user-guide/libraries/user_agent.html

-2
Jan 22 '14 at 22:32
source share



All Articles