Link to home
Start Free TrialLog in
Avatar of sabecs
sabecs

asked on

Detecting user's browser and operating system?

Hi,
Just wondering if anyone has a simple script written in JavaScript or PHP that will detect basic information about a user’s web browser and operating system and then write it to a file?

Thanks in advance for your feedback.
Avatar of Slimshaneey
Slimshaneey
Flag of United Kingdom of Great Britain and Northern Ireland image

Oops, my link no longer working! The other option is get_browser() function in PHP
Just searched around and this looks to do a similar job, incorporates mobile to so Im goin got play with it and possibly use on my own projects!

https://github.com/tobie/ua-parser
Have you considered using

http://statcounter.com/

It's free, easy, and keeps statistics for you about browsers, systems, and lots of other things.  No need to write the code yourself when you have this available.

If you need long term statistics, statcounter has a premium account for that which is very cheaply priced for all that you get.

By the way, there are php functions to retrieve the browser and other information, but they are notoriously unreliable.  $_ENV for example is supposed to contain a lot of this environmental information, but some browers simply don't fill it.  

Start with phpinfo() to see what variables are available on your system.

http://us3.php.net/manual/en/function.phpinfo.php
Yodercrm is right, stascounter is a great tool for that, I use Google Analytics for recording my browser info, its not as detailed though. You really only want to start messing with Browser Info if your script is going to specifically act on different types of browser.
Use the HTTP-Header for that.
$_SERVER('HTTP_USER_AGENT');

Open in new window


For example:
If a visitor is using google chrome to acces your site, the user agent will be:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11

If we break this up, you can see the windows version (Windows NT 6.1; WOW64), is Windows 7 (version 6.1), and 64bit (WOW64) Note: this is the architecture of the operating system, and not the browser used.

The browser version and name: Chrome/20.0.1132.47
Browser is Chrome, and version is 20.0.1132.47

So, using this server variable will get you all the information you ask for.
After that you can save it as you will.. In a file, in a database or whatever ;)

/Dennis
Avatar of sabecs
sabecs

ASKER

Thanks for your help, I need to track this info for customers that place orders online via a website. On some occasions I have problems with the order not being complete and need to determine if problems occur with specific users, browsers, operating systems etc...
Look at these variables...
// SHOW A PIECE OF THE SERVER ARRAY
var_dump($_SERVER["HTTP_USER_AGENT"]);
var_dump($_SERVER["HTTP_ACCEPT"]);

Open in new window

They are usually set and usually accurate.  I'll see if I can come up with a more complete code sample.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sabecs

ASKER

Thanks for your help, sorry for the late response...