Related articles
User agent detect
The User-Agent header contains a line of text that can be used to identify a user agent and client device.
Most of the time, we can find the device model and manufacturer from the User-Agent header.
It may also contain information such as the client device's OS version, browser version, Java capabilities, etc.
Some example User-Agent headers are provided below.
Microsoft Internet Explorer 6:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Mozilla Firefox 1.0.7:
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7
That is why for
user agent detect using patterns libraries, for example [Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 6.*)*] - patern of "IEMobile", [* (compatible; Googlebot-Mobile/2.1; *http://www.google.com/bot.html)] - pattern of "Googlebot-Mobile browser",
[AdsBot-Google (?http://www.google.com/adsbot.html)] pattern of "AdsBot-Google browser".
User agent browser
This application or script for information lookup. It is trivial enough to be translated in any language easily though. The first three methods are utilities, and the last two are the real detection: Browser and OS. The one in the middle is a helper to handle bots. In the code, some comments (in red) will guide you though the process.
The three methods returning a Browser/OS (the last three) actually return an array of three Strings, representing the element with three different levels of verbosity.
- The first element represent the class of the element (Win, Linux, MSIE, KHTML...)
- The second element represent the element reasonably detailed (Win98, WinXP, MSIE6, Gecko(Firebird)...)
- The last element represent element with all known details from the User-Agent (Linux2.4.24 i686, Windows NT 5.1, Gecko2005(Firebird0.8.0+), Opera7.23...), the only exception being Gecko for which I truncate the timestamp to the first four digits (the year) otherwise it gets unmanageable
User agent request header
User agent request header - it's part of request (request - information that sending to server [request method, url,...]), see example. Header can containg any string data, but as usualy it's looking like * (*) *.
HTTP_USER_AGENT | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.19) Gecko/20081216 Ubuntu/8.04 (hardy) Firefox/2.0.0.19 |
HTTP_ACCEPT | text/xml,application/xml,application/xhtml+xml,text/html; q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 |
HTTP_ACCEPT_LANGUAGE | en-us,en;q=0.5 |
HTTP_ACCEPT_ENCODING | gzip,deflate |
HTTP_ACCEPT_CHARSET | ISO-8859-1,utf-8;q=0.7,*;q=0.7 |
HTTP_KEEP_ALIVE | 300 |