Open In App

HTTP Headers - User-Agent

Last Updated : 30 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTTP header User-Agent is a request header that sends a characteristic string to web servers, allowing them to identify the Operating System (OS) and browser of the client making the request.

Every time your browser connects to a website, it includes the User-Agent field in the HTTP header. This information helps websites serve content tailored to different browsers and operating systems.

Since different browsers use varying formats, there is no standardized way of writing a User-Agent string. Furthermore, modern browsers often add significant amounts of information to the User-Agent field.

Syntax:

User-Agent: <product>/<product-version> <comment>

or

User-Agent: Mozilla/<version> (<system-information>) <platform> (<platform-details>) <extensions>

Directives:

There are three key directives in the HTTP headers "User-Agent":

  • product: This field identifies the product (e.g., browser) making the request.
  • product-version: This specifies the version of the product.
  • comment: This field includes additional information about the sub-product, system, and any extensions used by the client.

Example User-Agent Strings for Common Browsers

Different browsers and devices generate different User-Agent strings. Below are examples for various popular browsers:

Mozilla:

Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.3
Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/43.4

Google Chrome:

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36

Safari:

Mozilla/5.0 (iPhone; CPU iPhone OS 11_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) 
Version/10.0 Mobile/14E304 Safari/602.1

Why User-Agent Information Matters

The User-Agent field plays a critical role in web browsing because websites can use this information to customize the content they serve to your browser. For example:

  • Mobile vs Desktop Websites: Websites often serve different layouts to mobile and desktop browsers.
  • Browser Compatibility: Some sites may deliver different content based on your browser to ensure compatibility (e.g., Chrome vs Safari).
  • Security: Websites can detect and block unsupported or outdated browsers.



Next Article
Article Tags :

Similar Reads