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?
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.
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.
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.
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With