RSS

How-To Geek

Your browser sends its user agent to every website you connect to. We’ve written about changing your browser’s user agent before – but what exactly is a user agent, anyway?

A user agent is a “string” – that is, a line of text – identifying the browser and operating system to the web server. This sounds simple, but user agents have become a mess over time.

The Basics

When your browser connects to a website, it includes a User-Agent field in its HTTP header. The contents of the user agent field vary from browser to browser. Each browser has its own, distinctive user agent. Essentially, a user agent is a way for a browser to say “Hi, I’m Mozilla Firefox on Windows” or “Hi, I’m Safari on an iPhone” to a web server.

The web server can use this information to serve different web pages to different web browsers and different operating systems. For example, a website could send mobile pages to mobile browsers, modern pages to modern browsers, and a “please upgrade your browser” message to Internet Explorer 6.

The plot thickens: Chrome is pretending to be both Mozilla and Safari. To understand why, we’ll have to examine the history of user agents and browsers.

The User Agent String Mess

Mosaic was one of the first browsers. Its user agent string was NCSA_Mosaic/2.0. Later, Mozilla came along (later renamed Netscape), and its user agent was Mozilla/1.0. Mozilla was a more advanced browser than Mosaic – in particular, it supported frames. Web servers checked to see that the user agent contained the word Mozilla and sent pages containing frames to Mozilla browsers. To other browsers, web servers sent the old pages without frames.

Eventually, Microsoft’s Internet Explorer came along and it supported frames, too. However, IE didn’t receive web pages with frames, because web servers just sent those to Mozilla browsers. To fix this problem, Microsoft added the word Mozilla to their user agent and threw in additional information (the word “compatible” and a reference to IE.) Web servers were happy to see the word Mozilla and sent IE the modern web pages. Other browsers that came later did the same thing.

Eventually, some servers looked for the word Gecko – Firefox’s rendering engine – and served Gecko browsers different pages than older browsers. KHTML – originally developed for Konquerer on Linux’s KDE desktop – added the words “like Gecko” so they’d get the modern pages designed for Gecko, too. WebKit was based on KHTML – when it was developed, they added the word WebKit and kept the original “KHTML, like Gecko” line for compatibility purposes. In this way, browser developers kept adding words to their user agents over time.

Web servers don’t really care what the exact user agent string is – they just check to see if it contains a specific word.

Uses

Web servers use user agents for a variety of purposes, including:

Serving different web pages to different web browsers. This can be used for good – for example, to serve simpler web pages to older browsers – or evil – for example, to display a “This web page must be viewed in Internet Explorer” message.

Displaying different content to different operating systems – for example, by displaying a slimmed-down page on mobile devices.

Gathering statistics showing the browsers and operating systems in use by their users. If you ever see browser market-share statistics, this is how they’re acquired.

Web servers can give bots special treatment – for example, by allowing them through mandatory registration screens. (Yes, this means that you can sometimes bypass registration screens by setting your user agent to Googlebot.)

Web servers can also give orders to specific bots (or all bots) using the robots.txt file. For example a web server could tell a specific bot to go away, or tell another bot to only index certain areas of the website. In the robots.txt file, the bots are identified by their user agent strings.

All major browsers contain ways to set custom user agents, so you can see what web servers send to to different browsers. For example, set your desktop browser to a mobile browser’s user agent string and you’ll see the mobile versions of web pages on your desktop.

“The web server can use this information to serve different web pages to different web browser sand different operating systems. For example, a website could send mobile pages to mobile browsers, modern pages to modern browsers, and a “please upgrade your browser” message to Internet Explorer
6.”

Is there anyone out there who might unpack this paragraph for me. It is so frustrating to look for an explanation, and the explanation is more complex than the original concept.

Ozlock, I think you can interpret the paragraph as follows – when a web server gets a string containing the term «Mozilla/5.0», it shoots back a version of the requested web pages that suits that type of browser (a process that can be further refined by including other terms like, for example, «(KHTML, like Gecko)» ; should it receive a string which includes the term «MSIE 6.0x», it could be programmed to include a message suggesting that the user upgrade to a less dodgy browser. Likewise, when it receives a string identifying the browser as a mobile browser, it sends back a version of the page requested which hopefully displays correctly on that browser….

How would I go about tricking my desktop firefox into thinking it’s firefox mobile?

I love the mobile versions of sites as they allow me to enlarge text – and when it gets too big for the horizontal frame it pushes text onto the next line rather than making me scroll left and right. I’d like to use these on my desktop pcs.

I can use the Internet with the mentioned browsers but Not the”MSN Internet explorer”every time I try
Internet Explorer the message appears “internet can’t display the the web page”

The usual details appear on the ” Remedy Solutions” prominent one, Not connected to the Internet
and if one persevers a smaller notice pops-up stating that this problem not be tackled Internally, contact
I.S P.they say it is a repair shop job. Two repair shops have checked th PC and say there is nothing.
wrong.

Install the User Agent Switcher extension from Mozilla’s extensions website and select a mobile browser in the user agent menu — for example, you could select “iPhone” to get mobile sites.

@mr_g

Well, it’s particularly useful for mobile. For example, you might visit a news website on your smartphone and want a slimmed-down news layout, not a “please visit a PC to view this website” message. Many people can also not switch their browsers (forced to use a specific browser at their job) or don’t want to.

GEEK TRIVIA

DID YOU KNOW?

Since 2010 it’s been possible to make phone calls from the top of Mt. Everest thanks to 3G installed by telecommunications company NCell; a later addition by China Mobile and Huawei Wireless Networks in 2013 upgraded the coverage to 4G.