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.
JavaScriptPHP

Avatar of undefined
Last Comment
sabecs

8/22/2022 - Mon
Slimshaneey

Oops, my link no longer working! The other option is get_browser() function in PHP
Slimshaneey

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
Cornelia Yoder

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Slimshaneey

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.
artzter

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
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...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Ray Paseur

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
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
sabecs

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