Browser sniffing
There are many different web browsers available, and there will be even more in the future when Web-TV, small hand-held devices, etc. become popular. Unfortunately, the browsers are not completely standardized. When you make some advanced codes that work in one browser, it may not work in other browsers. A possible solution to this problem is to use a browser sniffer. This is a program that detects which browser the user has and provides the code that fits the users' browser. The browser sniffer can run either on the server or in the browser.
A browser identifies itself with a string called HTTP_USER_AGENT. Examples of this string are given in the table below.
| Browser | HTTP_USER_AGENT examples |
| Netscape | Mozilla/3.0 (Win95; I) |
| Mozilla/4.72 [en] (Win95; I) | |
| Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0 | |
| MS Internet Explorer | Mozilla/3.01 (compatible;) |
| Mozilla/4.0 (compatible; MSIE 4.01; Windows 98) | |
| Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt) | |
| Opera | Mozilla/4.0 (compatible; MSIE 5.0; Windows 98) Opera 5.02 [en] |
| Amaya | amaya/V2.4 libwww/5.2.8 |
| Lynx | Lynx/2.8.3rel.1 libwww-FM/2.14 |
| WebTV | Mozilla/3.0 WebTV/1.2 (compatible; MSIE 2.0) |
| The browser you are using right now! | CCBot/1.0 (+http://www.commoncrawl.org/bot.html) |
Mozilla is the same as Netscape. This was the first graphical browser that became available and therefore, other browsers identify as Mozilla to specify that they are (almost) compatible with Mozilla. For example, the string "Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)" identifies a Microsoft Internet Explorer version 5.01, which is compatible with Mozilla version 4. If the string has no other name than Mozilla, and does not have the word "compatible", then it is a Netscape.
The task of the browser sniffer is to analyze the identifying string to find out which browser it is. The links below give examples of browser sniffers in different programming languages. The easiest method to use is PHP.
- Browser-side browser sniffer
- JavaScript
- Server-side browser sniffer
- server-side include
- PHP
C++
perl
For further information, search the web for "browser sniffer".
This page was last modified 2008-Dec-08
