标题：useragent
含义
User Agent中文名为用户代理，简称 UA，它是一个特殊字符串头，使得服务器能够识别客户使用的操作系统及版本、CPU 类型、浏览器及版本、浏览器渲染引擎、浏览器语言、浏览器插件等。 
一些网站常常通过判断 UA 来给不同的操作系统、不同的浏览器发送不同的页面，因此可能造成某些页面无法在某个浏览器中正常显示，但通过伪装 UA 可以绕过检测。浏览器 的 UA 字串标准格式为： 浏览器标识 (操作系统标识; 加密等级标识; 浏览器语言) 渲染引擎标识 版本信息浏览器标识由于很多网站在进行 UA 检测的时候忽略了两位数版本号，所以可能造成 浏览器及之后版本收到糟糕的页面，因此自 浏览器 10 之后的版本中浏览器标识项固定为 浏览器，在 UA 字串尾部添加真实版本信息。
语法
英文资料
Some common user agent strings dissected
This list is incomplete; you can help by expanding it.
[edit] Internet Explorer, and browsers cloaking as Internet Explorer
Mozilla/MozVer (compatible; MSIE IEVer[; Provider]; Platform[; Extension]*) [Addition]
Where:
* MozVer: Netscape compatibility version
o 1.22: Internet Explorer 1.5 and 2.0
o 2.0: Internet Explorer 3.x for Windows and Internet Explorer 2.1 for Mac
o 3.0: Internet Explorer 3.x for Mac
o 4.0: Internet Explorer 4.x and higher
* IEVer: Internet Explorer version number, e.g.: 1.5, 3.01, 5.0b1, 6.0
* Provider: Access provider, e.g.:
o AOL Version
o America Online Browser Version; revRevision: AOL Explorer (note, this breaks the rule of no semicolons in Provider values)
o CS 2000
o MSN Version
o This parameter is included but empty on some Opera distributions, resulting in "semicolon space semicolon":
; ;
* Platform: Operating system, e.g.:
o Windows 3.1 (including Windows NT 3.x)
o Windows 95
o Windows 98
o Windows 98; Win 9x 4.90: Windows Millennium Edition (Windows Me)
o Windows NT
o Windows NT 4.0
o Windows NT 5.0: Windows 2000
o Windows 2000: Windows 2000 (used by Opera)
o Windows NT 5.01: Windows 2000, Service Pack 1 (SP1)
o Windows NT 5.1: Windows XP
o Windows NT 5.2: Windows Server 2003
o Windows NT 6.0: Windows Vista
o Windows CE: Windows CE and Windows Mobile (used by Internet Explorer Mobile)
o Win32: Seen with IE 7b1 on Windows XP
o Mac_68000
o Mac_PPC: Used up until IE 4.x
o Mac_PowerPC: Used from IE 5.x and up
o SunOS Version: SunOS
o Symbian OS: Used by Opera on mobile phones
o Nitro: Nintendo DS (used by Opera)
* Extension: optional, a list of semicolon-separated extensions installed, e.g.:
o .NET CLR Version: .NET Framework common language runtime installed (may appear multiple times, e.g. when both 1.1 and 2.0 are supported)
o SV1: Internet Explorer 6 in Windows XP SP2 and Windows Server 2003 SP1 installed
o Tablet PC Version: Tablet services are installed
o Win64: 64-bit Windows
o IA64: Intel Itanium processor
o AMD64: x64 processor
o x64: x64 processor
o WOW64: 32-bit Internet Explorer is running on 64-bit Windows
o Media Center PC Version: Windows MCE, where Version is:
+ 2.8: Media Center 2004
+ 3.0: Media Center 2005
+ 3.1: Media Center 2005 with update rollup 1
+ 4.0: Media Center 2005 with update rollup 2
+ 5.0: Windows Vista Home Premium or Ultimate edition.
o MediaCenter Version: browsing from within Media Center interface
o MSIECrawler: MSIE retrieving pages for Offline Content feature
o X11: Internet Explorer on SunOS
o PPC: Pocket PC (used by Internet Explorer Mobile)
o Smartphone: Smartphone (used by Internet Explorer Mobile)
o Motorola Type: Internet Explorer Mobile on Motorola mobile phone
o Nokia Type/Version: Opera on Nokia mobile phone
o Various 3rd party browser extensions, like: (R1 Version) (RealPlayer webbrowser), Alexa Toolbar, Maxthon, Crazy Browser Version, MyIE2, Avant Browser,FDM
o Language: some Opera versions seem to include the language code here (seen for Opera 8.5 on Windows XP)
o WidthxHeight: some Internet Explorer Mobile browsers include the display resolution here
* Addition
o Netscape/Version: Netscape using MSHTML rendering engine
o Opera Version [Language]: Opera cloaked as Internet Explorer
Example:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
[edit] Internet Explorer 1.0
Internet Explorer 1.0 used an alternative user agent:
Microsoft Internet Explorer/Version (Platform)
Where:
* Version: Windows version because IE was originally supposed to be included with Windows 95, e.g.: 4.0b1 for Internet Explorer 1.0 beta
* Platform: operating system, e.g.: Windows 95
[edit] Netscape
This only applies to earlier versions of Netscape. Netscape 6.0 or higher based on the Gecko engine should see the Mozilla section below
Mozilla/Version[Gold] [[Language]][Provider] (Platform; Security[; SubPlatform][StandAlone])
Where:
* Version: version number
* Gold: includes HTML editor
* Language: standardized two-letter language identifier, e.g.: en, fr, es (Netscape 2.x and 3.x: only for non-English versions, Netscape 4.x: not on Macintosh platforms?)
* Provider, may contain variants of C-CCK-MCD (Client Customization Kit and Mission Control Desktop, for ISPs and OEMs)
* Platform
o Win16: Windows 3.x
o Win95: Windows 95, where SubPlatform can be:
+ 16bit for 16-bit version of Netscape
o Win98: Windows 98
o WinNT: Windows NT 3.x
o Windows NT 5.0: Windows 2000
o Windows NT 5.1: Windows XP
o X11, where SubPlatform is:
+ Distribution Version [Subversion], e.g.: Linux i586, SunOS 5.6 sun4u, IRIX 6.5 IP32
o Macintosh, where SubPlatform is:
+ 68K
+ PPC
+ Intel
* Security
o U: strong security (USA)
o I: weak security (International)
o N: no security
* StandAlone: standalone Navigator is indicated by ; Nav (X11 platforms), ;Nav (Windows, note missing space) or , Nav (on Macintosh), only for version 4.x
[edit] Mozilla
Mozilla/MozVer (Platform; Security; SubPlatform; Language; rv:Revision[; Extension]*) Gecko/GeckVer [Product/ProdVer]
Where:
* MozVer: Netscape compatibility version
o 5.0 for all known Mozilla browsers
* Platform and SubPlatform
o Windows
+ Win3.11: Windows 3.11
+ Win95: Windows 95
+ Win98: Windows 98
+ Win 9x 4.90: Windows Me
+ WinNT3.51: Windows NT 3.51
+ WinNT4.0: Windows NT 4.0
+ Windows NT 5.0: Windows 2000
+ Windows NT 5.1: Windows XP (except XP Professional x64 Edition)
+ Windows NT 5.2: Windows Server 2003 and Windows XP Professional x64 Edition
+ Windows NT 6.0: Windows Vista
+ Windows CE 4.21: Windows Mobile 2003
o Macintosh
+ PPC Mac OS X
+ PPC Mac OS X Mach-O
+ Intel Mac OS X
o X11
+ Linux [Version] Hardware
+ FreeBSD Hardware
+ NetBSD Hardware
+ SunOS Hardware
* Security
o U: strong security (USA)
o I: weak security (International)
o N: no security
* Language: standardized language identifier, e.g.: en, en-US, en-GB
* Revision: e.g. m18, 1.0rc3, 1.7.8, 1.8a2
* Extension
o MultiZilla Version
* GeckVer: Gecko (layout engine) compilation date, in the format YYYYMMDD
* Product
o For the Mozilla Application Suite, there is no Product or ProdVer. The Revision is the product version.
o Netscape, Netscape6
o Phoenix, Firebird, Firefox, GranParadiso (Firefox 3 codename), Minefield (trunk build)
o K-Meleon
o Minimo
o SeaMonkey
o Camino
o CS 2000 7.0
* ProdVer: Product version
[edit] Encryption strength "U" / "I" / "N"
Netscape, Mozilla, Opera and some others use one of these three letters to specify the browser's encryption strength. Since the US government formerly wouldn't allow encryption higher than 40-bit to be exported from the USA, different versions were released with different encryption strengths. "U" stands for "USA" (for the version with 128-bit encryption), "I" stands for "International" (the browser has 40-bit encryption and can be used anywhere in the world), "N" stands for "None" (no encryption). Originally the "U" version was allowed for download only from the USA, but since then the US government has loosened its policy and exporting high encryption is now permitted to most countries (see Export of cryptography for more information). Now Netscape and Mozilla distribute their browsers only in a "U" version, supporting up to 256-bit encryption, since an international version is no longer required.
实例
<html> 
<body> 
<script type="text/javascript"> 
document.write("<p>UserAgent: ") 
document.write(navigator.userAgent + "</p>") 
</script> 
</body> 
</html>
历史变迁
WebKit2003年，Apple 宣布发布首款他们自主开发的 web 浏览器：Safari。它的呈现引擎叫 WebKit。它是 Linux 中的 web 浏览器 Konqueror 呈现引擎 KHTML 的一个分支，几年后，WebKit 的开源吸引了呈现引擎的开发人员。 　这款新浏览器和呈现引擎的开发人员也遇到了曾经 IE 3.0 类似的问题：怎样才能溶入主流而不被踢出局？答案是：在 user-agent 字串中放详尽的信息，以便骗取网站的信任使它与其它流行的浏览器兼容。user-agent 字串格式如下： 　Mozilla/5.0 (Platform; Encryption; OS-or-CPU; Language) AppleWebKit/AppleWebKitVersion (KHTML, like Gecko) Safari/SafariVersion下面是示例： 　Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/124 (KHTML, like Gecko) Safari/125.1这又是个挺长的 user-agent 字串，其中包括的信息既有 Apple WebKit 的版本，也有 Safari 的版本。凡是基于 WebKit 的浏览器都将自己伪装成了 Mozilla 5.0，与基于 Gecko 浏览器完全一样。但 Safari 的版本是浏览器的构建版本号(build number)。Safari 1.25 在 user-agent 字串中号为 125.1(如上所示)。Safari 版本 3 的 user-agent 字串包括了实际的 Safari 版本： 　Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/522.15.5 (KHTML, like Gecko) Version/3.0.3 Safari/522.15.5其中的“(KHTML, like Gecko)”在 Safari 1.0 预览版本中就有了，这字串部分是最耐人寻味又饱受诟病。Apple 的野心是为了让开发人员把 Safari 当成 Gecko，所以采取了当初微软 IE user-agent 的类似做法：Safari 是兼容 Mozilla 的，否则 Safari 用户会认为用的浏览器不受支持。 　而其它基于 WebKit 的浏览器与 Safari 不同的是，没有上面说的这个情况，所以检测断定浏览器是否基于 WebKit 比看有没有明确标 Safari 更有用。KonquerorKonqueror 是款在 KDE Linux 桌面环境中的浏览器，基于 KHTML 开源呈现引擎。它只发布了在 Linux 的版本，但是拥有活跃的用户群。为了兼容性最大化，user-agent 字串的格式也紧跟 IE 的后尘： 　Mozilla/5.0 (compatible; Konqueror/Version; OS-or-CPU)Konqueror 3.2 为了与 WebKit user-agent 字串变化保持一致，它将 KHTML 作为它的标识： 　Mozilla/5.0 (compatible; Konqueror/Version; OS-or-CPU) KHTML/KHTMLVersion (like Gecko)如下所示： 　Mozilla/5.0 (compatible; Konqueror/3.5; SunOS) KHTML/3.5.0 (like Gecko)Konqueror 和 KHTML 的版本号比较一致，唯一的区别就是下点处不同，比如Konquerer 3.5、KHTML 3.5.1。ChromeGoogle Chrome 浏览器以 WebKit 作为呈现引擎，JavaScript 引擎却用了另一种。最初发布的版本是 0.2，它的 user-agent 字串格式是在 webKit 信息的基础上又增加了如下： 　Mozilla/5.0 (Platform; Encryption; OS-or-CPU; Language) AppleWebKit/AppleWebKitVersion (KHTML, like Gecko) Chrome/ChromeVersion Safari/SafariVersionChrome 0.2 user-agent 信息的示例如下： 　Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13虽我不敢完全保证，但很可能 WebKit 版本和 Safari 版本总会保持同步。OperaOpera 浏览器默认 user-agent 字串是现代浏览器中最合理的－－正确的标识了它自己及其版本。 在 Opera 8.0 前，它的 user-agent 字串格式如下： 　Opera/Version (OS-or-CPU; Encryption) [Language]在 Windows XP 中 Opera 7.54 user-agent 字串示例： 　Opera/7.54 (Windows NT 5.1; U) [en]Opera 8 user-agent 字串的语言部分移到了括号内。 　Opera/Version (OS-or-CPU; Encryption; Language)在 Windows XP 中 Opera 8 user-agent 字串示例： 　Opera/8.0 (Windows NT 5.1; U; en)当时 Opera 做为主流浏览器之一，它的 user-agent 字串是唯一使用产品名称和版本完全真实的标识了它自己。但是由于大量的浏览器嗅探代码在 Internet 上像蝗虫飞过般只吃标 Mozilla 产品名的 user-agent 字串，造成了 Opera 的 user-agent 字串发生了完全的改变。 　Opera 9 user-agent 字串有两种修改的方式：一种方式是将自己标识为 Firefox 或 IE 浏览器。在这种方式下，user-agent 字串与 Firefox 或 IE 的几乎一样，只不过末尾附加了“Opera”及版本号。如下所示： 　Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.50前一字串将 Opera 9.5 标识为 Firefox 2。后一字串将 Opera 9.5 标识为 IE 6，在两个字串中都带有 Opera 版本信息。虽然这种方式是作为 Firefox 或 IE 打开的，但也能识别出 Opera。另一种方法则是浏览器 user-agent 字串标识伪装成 Firefox 或 IE，同时也找不到“Opera”字串及其版本信息。这样从字面上去区分 Opera 浏览器便成了“不可能完成的任务”。