1BrowserDetect(3) User Contributed Perl Documentation BrowserDetect(3)
2
3
4
6 HTTP::BrowserDetect - Determine the Web browser, version, and platform
7 from an HTTP user agent string
8
10 use HTTP::BrowserDetect;
11
12 my $browser = new HTTP::BrowserDetect($user_agent_string);
13
14 # Detect operating system
15 if ($browser->windows) {
16 if ($browser->winnt) ...
17 if ($brorwser->win95) ...
18 }
19 print $browser->mac;
20
21 # Detect browser vendor and version
22 print $browser->netscape;
23 print $browser->ie;
24 if (browser->major(4)) {
25 if ($browser->minor() > .5) {
26 ...
27 }
28 }
29 if ($browser->version() > 4) {
30 ...;
31 }
32
33 # Process a different user agent string
34 $browser->user_agent($another_user_agent_string);
35
37 The HTTP::BrowserDetect object does a number of tests on an HTTP user
38 agent string. The results of these tests are available via methods of
39 the object.
40
41 This module is based upon the JavaScript browser detection code avail‐
42 able at http://www.mozilla.org/docs/web-developer/snif‐
43 fer/browser_type.html.
44
45 CREATING A NEW BROWSER DETECT OBJECT AND SETTING THE USER AGENT STRING
46
47 new HTTP::BrowserDetect($user_agent_string)
48 The constructor may be called with a user agent string specified.
49 Otherwise, it will use the value specified by
50 $ENV{'HTTP_USER_AGENT'}, which is set by the web server when call‐
51 ing a CGI script.
52
53 You may also use a non-object-oriented interface. For each method,
54 you may call HTTP::BrowserDetect::method_name(). You will then be
55 working with a default HTTP::BrowserDetect object that is created
56 behind the scenes.
57
58 user_agent($user_agent_string)
59 Returns the value of the user agent string. When called with a
60 parameter, it resets the user agent and reperforms all tests on the
61 string. This way you can process a series of user agent strings
62 (from a log file, perhaps) without creating a new HTTP::BrowserDe‐
63 tect object each time.
64
65 DETECTING BROWSER VERSION
66
67 major($major)
68 Returns the integer portion of the browser version. If passed a
69 parameter, returns true if it equals the browser major version.
70
71 minor($minor)
72 Returns the decimal portion of the browser version as a floating-
73 point number less than 1. For example, if the version is 4.05,
74 this method returns .05; if the version is 4.5, this method returns
75 .5. This is a change in behavior from previous versions of this
76 module, which returned a string.
77
78 If passed a parameter, returns true if equals the minor version.
79
80 On occasion a version may have more than one decimal point, such as
81 'Wget/1.4.5'. The minor version does not include the second decimal
82 point, or any further digits or decimals.
83
84 version($version)
85 Returns the version as a floating-point number. If passed a param‐
86 eter, returns true if it is equal to the version specified by the
87 user agent string.
88
89 beta($beta)
90 Returns any the beta version, consisting of any non-numeric charac‐
91 ters after the version number. For instance, if the user agent
92 string is 'Mozilla/4.0 (compatible; MSIE 5.0b2; Windows NT)',
93 returns 'b2'. If passed a parameter, returns true if equal to the
94 beta version. If the beta starts with a dot, it is thrown away.
95
96 DETECTING OS PLATFORM AND VERSION
97
98 The following methods are available, each returning a true or false
99 value. Some methods also test for the operating system version. The
100 indentations below show the hierarchy of tests (for example, win2k is
101 considered a type of winnt, which is a type of win32)
102
103 windows
104 win16 win3x win31
105 win32
106 winme win95 win98
107 winnt
108 win2k winxp
109 dotnet
110
111 mac
112 mac68k macppc macosx
113
114 os2
115
116 unix
117 sun sun4 sun5 suni86 irix irix5 irix6 hpux hpux9 hpux10
118 aix aix1 aix2 aix3 aix4 linux sco unixware mpras reliant
119 dec sinix freebsd bsd
120
121 vms
122
123 amiga
124
125 It may not be possibile to detect Win98 in Netscape 4.x and earlier.
126 On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
127 Win32, so you can't distinguish between Win95 and WinNT.
128
129 os_string()
130 Returns one of the following strings, or undef. This method exists
131 solely for compatibility with the HTTP::Headers::UserAgent module.
132
133 Win95, Win98, WinNT, Win2K, WinXP, Mac, Mac OS X, Win3x, OS2, Unix, Linux
134
135 DETECTING BROWSER VENDOR
136
137 The following methods are available, each returning a true or false
138 value. Some methods also test for the browser version, saving you from
139 checking the version separately.
140
141 netscape nav2 nav3 nav4 nav4up nav45 nav45up navgold nav6 nav6up
142 gecko
143 mozilla
144 firefox
145 safari
146 ie ie3 ie4 ie4up ie5 ie55 ie6
147 neoplanet neoplanet2
148 mosaic
149 aol aol3 aol4 aol5 aol6
150 webtv
151 opera opera3 opera4 opera5 opera6 opera7
152 lynx links
153 emacs
154 staroffice
155 lotusnotes
156 icab
157 konqueror
158 java
159 curl
160
161 Netscape 6, even though its called six, in the userAgent string has
162 version number 5. The nav6 and nav6up methods correctly handle this
163 quirk. The firefox text correctly detects the older-named versions of
164 the browser (Phoenix, Firebird)
165
166 browser_string()
167 Returns one of the following strings, or undef.
168
169 Netscape, MSIE, WebTV, AOL Browser, Opera, Mosaic, Lynx
170
171 gecko_version()
172 If a Gecko rendering engine is used (as in Mozilla or Firebird),
173 returns the version of the renderer (e.g. 1.3a, 1.7, 1.8) This
174 might be more useful than the particular browser name or version
175 when correcting for quirks in different versions of this rendering
176 engine. If no Gecko browser is being used, or the version number
177 can't be detected, returns undef.
178
179 DETECTING OTHER DEVICES
180
181 The following methods are available, each returning a true or false
182 value.
183
184 wap
185 audrey
186 iopener
187 palm
188 avantgo
189 blackberry
190
191 DETECTING ROBOTS
192
194Returns true if the user agent appears to be a robot, spider, crawler, or
195other automated Web client.
196
197The following additional methods are available, each returning a true or false
198value. This is by no means a complete list of robots that exist on the Web.
199
200 wget
201 getright
202 yahoo
203 altavista
204 lycos
205 infoseek
206 lwp
207 webcrawler
208 linkexchange
209 slurp
210 google
211
213 Lee Semel, lee@semel.net
214
215 Thanks to Leonardo Herrera for additional contributions
216
218 "The Ultimate JavaScript Client Sniffer, Version 3.0",
219 http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html.
220
221 "Browser ID (User-Agent) Strings"
222 http://www.zytrax.com/tech/web/browser_ids.htm
223
224 perl(1), HTTP::Headers, HTTP::Headers::UserAgent.
225
227 Copyright 1999-2004 Lee Semel. All rights reserved. This program is
228 free software; you can redistribute it and/or modify it under the same
229 terms as Perl itself.
230
231
232
233perl v5.8.8 2004-06-22 BrowserDetect(3)