Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code to parse user agent string?

As strange as I find this, I have not been able to find a good PHP function anywhere which will do an intelligent parse of a user agent string? Googled it for about 20 minutes now.

I have the string already, I just need something that will chop it up and give me at least browser/ver/os.

Know of a good snippet anywhere?

like image 824
Spot Avatar asked Jan 23 '10 10:01

Spot


People also ask

What is parse user agent?

Every time your web browser makes a request to a website, it sends a HTTP Header called the "User Agent". The User Agent string contains information about your web browser name, operating system, device type and lots of other useful bits of information.

What is a user agent string?

A browser's User-Agent string (UA) helps identify which browser is being used, what version, and on which operating system. When feature detection APIs are not available, use the UA to customize behavior or content to specific browser versions.

Where is the user agent string?

The User-Agent (UA) string is contained in the HTTP headers and is intended to identify devices requesting online content. The User-Agent tells the server what the visiting device is (among many other things) and this information can be used to determine what content to return.


2 Answers

The get_browser() function has been available in PHP for quite a long a time.

The PHP manual is free, can be downloaded in various formats and viewed online (with comments)

like image 85
symcbean Avatar answered Sep 20 '22 16:09

symcbean


https://github.com/browscap/browscap-php - this is a standalone library that aims to replace get_browser function. For shared hostings it seems to be a better option.

Works on: PHP 5

like image 41
Martin Vseticka Avatar answered Sep 19 '22 16:09

Martin Vseticka