59
votes

Is there an RFC, official standard, or template for creating a User Agent string? The iphone's user-agent string seems strange...

Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16

3
The iPhone seriously puts Mozilla/5.0 at the beginning of it's user agent?Tarka
@Slokun why the surprise? IE user-agent starts with Mozilla/4.0. Remember that Mozilla one of the first browsers to be made, and all others include, to various degrees, parts of its foundation.Paulo Santos
The explanation on useragentstring.com is that it should just mean Gecko-based browsers (Netscape and Firefox) but most other browsers include it to say they're Mozilla-compatible.Rikki
Think of Mozilla/ as "not Lynx". Generally text-only = not Mozilla-compatible. Some old WML/HDML feature-phone browsers also don't identify as Mozilla. (Fun fact: all the browsers before Lynx died of dysentery or were eaten by grues.)Webveloper

3 Answers

71
votes

The User-Agent header is part of the RFC7231, which is an improved version of the RFC1945, where it states:

The User-Agent request-header field contains information about the user agent originating the request. This is for statistical purposes, the tracing of protocol violations, and automated recognition of user agents for the sake of tailoring responses to avoid particular user agent limitations. User agents SHOULD include this field with requests. The field can contain multiple product tokens (section 3.8) and comments identifying the agent and any subproducts which form a significant part of the user agent. By convention, the product tokens are listed in order of their significance for identifying the application.

   User-Agent     = "User-Agent" ":" 1*( product | comment )

Where product is defined as:

   product         = token ["/" product-version]
   product-version = token
   token           = 1*<any CHAR except CTLs or separators>

And comment as:

   comment        = "(" *( ctext | quoted-pair | comment ) ")"
   ctext          = <any TEXT excluding "(" and ")">
11
votes

This is specified in RFC 1945 in the section on Request Headers. It is not a very standardized format, though, and user agents tend to put whatever they want in there.

3
votes

Yes, see: mozilla website, but as it was mentioned before. Basically you can put whatever you want there. For statistical/analytical purposes, the most important thing is, that every browser/os should have this standardized for itself.