views:

4099

answers:

7

Hello,

I was ondering if there is a way I can detect the exact OS version from my browser using PHP/JS/ASP?

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

Thanks,

Roy.

+8  A: 

Short answer: You can't.

Long answer:

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

Usually, browsers running on Mac OS and Linux send enough information to identify the exact OS. For example, here's my 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'm running Ubuntu 8.10 Intrepid Ibex.

And here's what Firefox and Safari 4 Beta report 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; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16

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

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

Can Berk Güder
Maybe its possible via Flash?
Roy Peleg
@Roy: maybe, but I wouldn't bet on it.
Can Berk Güder
And note that even this isn't foolproof. For example, changing your user-agent string to report something else is trivial in Firefox (download plugin) and almost trivial in IE (registry change).
John Feminella
Don't need a foolproof solution, but something which will give me say 90% accuracy. But as things seems not, its not feasible.
Roy Peleg
There are even non-browser programs (ftp, download managers) that allow the user to set the browser they will identify themselves as.
jeroen
+1  A: 

Ask the user? That's as close as you'll get...

Ward Werbrouck
+1  A: 

I don't think you'll be able to differentiate different versions of Vista, but you should be able to get the OS from the navigator object's platform property. You'll probably have to parse it, though, or differentiate based on it's contents.

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

See www.w3schools.com tutorials for an example showing how to get all the navigator's properties.

EDIT:

To get the exact version, you may be able to develop an ActiveX control (Windows only) or Java Applet and use the java.lang.System object to view the current system properties. You may be able to get enough information from the browser for non-Windows systems and use the control only for Windows systems. I haven't tried this, so you'd need to experiment to see if it would work. I have to believe that Microsoft's ActiveX control for Microsoft Update is able to detect the exact system version and installed software for it to work.

tvanfosson
As you said, this won't help to differentiate the sub versions, but thanks for the snippet :-)
Roy Peleg
+2  A: 

You should really try to avoid doing something like that unless it's absolutely necessary for the functionality of the web application.

Be aware that:

Not all requests can come from a client running on windows.

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

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

What is in the user-agent header may be missleading.

A well designed web application should provide complete content and functionality regardless of what's in the user-agent header of the request or if the client supports javascript or any other clientside extension.

Vasil
Thanks, will keep that in mind.
Roy Peleg
+1  A: 

As others have already said, no, not reliably.

That is the reason that for example jquery has switched to a browser-capabilities system (for lack of a better word) instead of a browser-sniffing system for it´s functionalities.

jeroen
+1  A: 

In Classic ASP and ASP.NET use

Request.ServerVariables("HTTP_USER_AGENT")

This works best since it's not interpreted code, this is running on the server.

Danny G
always good to have working code or suggestion for what property to examine
MikeJ
+3  A: 
Reed Richards
Not really what he wanted to do though is it? :)
willcodejavaforfood
This will not detect the exact OS package(say xp home vista ultimate ) of windows
NightCoder