1HTTP::BrowserDetect(3)User Contributed Perl DocumentationHTTP::BrowserDetect(3)
2
3
4

NAME

6       HTTP::BrowserDetect - Determine Web browser, version, and platform from
7       an HTTP user agent string
8

VERSION

10       Version 1.10
11

SYNOPSIS

13           use HTTP::BrowserDetect;
14
15           my $browser = new HTTP::BrowserDetect($user_agent_string);
16
17           # Detect operating system
18           if ($browser->windows) {
19             if ($browser->winnt) ...
20             if ($browser->win95) ...
21           }
22           print $browser->mac;
23
24           # Detect browser vendor and version
25           print $browser->netscape;
26           print $browser->ie;
27           if (browser->major(4)) {
28           if ($browser->minor() > .5) {
29               ...
30           }
31           }
32           if ($browser->version() > 4) {
33             ...;
34           }
35
36           # Process a different user agent string
37           $browser->user_agent($another_user_agent_string);
38

DESCRIPTION

40       The HTTP::BrowserDetect object does a number of tests on an HTTP user
41       agent string. The results of these tests are available via methods of
42       the object.
43
44       This module is based upon the JavaScript browser detection code
45       available at
46       http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html.
47

INSTALLATION

49       In most cases, you can just issue the following commands:
50
51         perl Build.PL
52         ./Build
53         ./Build test
54         ./Build install
55
56       Please see the documentation for Module::Build if you have questions
57       about installing to custom locations etc.
58

CONSTRUCTOR AND STARTUP

60   new()
61           HTTP::BrowserDetect->new( $user_agent_string )
62
63       The constructor may be called with a user agent string specified.
64       Otherwise, it will use the value specified by $ENV{'HTTP_USER_AGENT'},
65       which is set by the web server when calling a CGI script.
66
67       You may also use a non-object-oriented interface. For each method, you
68       may call HTTP::BrowserDetect::method_name(). You will then be working
69       with a default HTTP::BrowserDetect object that is created behind the
70       scenes.
71

SUBROUTINES/METHODS

73   user_agent($user_agent_string)
74       Returns the value of the user agent string. When called with a
75       parameter, it resets the user agent and reperforms all tests on the
76       string. This way you can process a series of user agent strings (from a
77       log file, perhaps) without creating a new HTTP::BrowserDetect object
78       each time.
79
80   country()
81       Returns the country string as it may be found in the user agent string.
82       This will be in the form of an upper case 2 character code. ie: US, DE,
83       etc
84
85   language()
86       Returns the language string as it is found in the user agent string.
87       This will be in the form of an upper case 2 character code. ie: EN, DE,
88       etc
89
90   device()
91       Returns the method name of the actual hardware, if it can be detected.
92       Currently returns one of: blackberry, iphone, ipod or ipad  Returns
93       UNDEF if no hardware can be detected
94
95   device_name()
96       Returns a human formatted version of the hardware device name.  These
97       names are subject to change and are really meant for display purposes.
98       You should use the device() method in your logic.  Returns one of:
99       BlackBerry, iPhone, iPod or iPad.  Returns UNDEF if no hardware can be
100       detected.
101

Detecting Browser Version

103       Please note that that the version(), major() and minor() methods have
104       been superceded as of release 1.07 of this module. They are not yet
105       deprecated, but should be replaced with public_version(),
106       public_major() and public_minor() in new development.
107
108       The reasoning behind this is that version() method will, in the case of
109       Safari, return the Safari/XXX numbers even when Version/XXX numbers are
110       present in the UserAgent string. Because this behaviour has been in
111       place for so long, some clients may have come to rely upon it. So, it
112       has been retained in the interest of "bugwards compatibility", but in
113       almost all cases, the numbers returned by public_version(),
114       public_major() and public_minor() will be what you are looking for.
115
116   public_version()
117       Returns the browser version as a floating-point number.
118
119   public_major()
120       Returns the integer portion of the browser version.
121
122   public_minor()
123       Returns the decimal portion of the browser version as a floating-point
124       number less than 1. For example, if the version is 4.05, this method
125       returns .05; if the version is 4.5, this method returns .5.
126
127       On occasion a version may have more than one decimal point, such as
128       'Wget/1.4.5'. The minor version does not include the second decimal
129       point, or any further digits or decimals.
130
131   version($version)
132       Returns the version as a floating-point number. If passed a parameter,
133       returns true if it is equal to the version specified by the user agent
134       string.
135
136   major($major)
137       Returns the integer portion of the browser version. If passed a
138       parameter, returns true if it equals the browser major version.
139
140   minor($minor)
141       Returns the decimal portion of the browser version as a floating-point
142       number less than 1. For example, if the version is 4.05, this method
143       returns .05; if the version is 4.5, this method returns .5. This is a
144       change in behavior from previous versions of this module, which
145       returned a string.
146
147       If passed a parameter, returns true if equals the minor version.
148
149       On occasion a version may have more than one decimal point, such as
150       'Wget/1.4.5'. The minor version does not include the second decimal
151       point, or any further digits or decimals.
152
153   beta($beta)
154       Returns any the beta version, consisting of any non-numeric characters
155       after the version number. For instance, if the user agent string is
156       'Mozilla/4.0 (compatible; MSIE 5.0b2; Windows NT)', returns 'b2'. If
157       passed a parameter, returns true if equal to the beta version. If the
158       beta starts with a dot, it is thrown away.
159

Detecting Rendering Engine

161   engine_string()
162       Returns one of the following:
163
164       Gecko, KHTML, MSIE
165
166       Returns undef if no string can be found.
167
168   engine_version()
169       Returns the version number of the rendering engine. Currently this only
170       returns a version number for Gecko. Returns undef for all other
171       engines.
172
173   engine_major()
174       Returns the major version number of the rendering engine. Currently
175       this only returns a version number for Gecko. Returns undef for all
176       other engines.
177
178   engine_minor()
179       Returns the minor version number of the rendering engine. Currently
180       this only returns a version number for Gecko. Returns undef for all
181       other engines.
182

Detecting OS Platform and Version

184       The following methods are available, each returning a true or false
185       value.  Some methods also test for the operating system version. The
186       indentations below show the hierarchy of tests (for example, win2k is
187       considered a type of winnt, which is a type of win32)
188
189   windows()
190           win16 win3x win31
191           win32
192               winme win95 win98
193               winnt
194                   win2k winxp win2k3 winvista win7
195
196   dotnet()
197   mac()
198       mac68k macppc macosx
199
200   os2()
201   unix()
202         sun sun4 sun5 suni86 irix irix5 irix6 hpux hpux9 hpux10
203         aix aix1 aix2 aix3 aix4 linux sco unixware mpras reliant
204         dec sinix freebsd bsd
205
206   vms()
207   amiga()
208       It may not be possibile to detect Win98 in Netscape 4.x and earlier. On
209       Opera 3.0, the userAgent string includes "Windows 95/NT4" on all Win32,
210       so you can't distinguish between Win95 and WinNT.
211
212   os_string()
213       Returns one of the following strings, or undef. This method exists
214       solely for compatibility with the HTTP::Headers::UserAgent module.
215
216         Win95, Win98, WinNT, Win2K, WinXP, Win2K3, WinVista, Win7, Mac, Mac OS X,
217         Win3x, OS2, Unix, Linux
218

Detecting Browser Vendor

220       The following methods are available, each returning a true or false
221       value.  Some methods also test for the browser version, saving you from
222       checking the version separately.
223
224       netscape nav2 nav3 nav4 nav4up nav45 nav45up navgold nav6 nav6up
225
226       gecko
227
228       mozilla
229
230       firefox
231
232       safari
233
234       chrome
235
236       ie ie3 ie4 ie4up ie5 ie55 ie6 ie7 ie8
237
238       neoplanet neoplanet2
239
240       mosaic
241
242       aol aol3 aol4 aol5 aol6
243
244       webtv
245
246       opera opera3 opera4 opera5 opera6 opera7
247
248       lynx links
249
250       emacs
251
252       staroffice
253
254       lotusnotes
255
256       icab
257
258       konqueror
259
260       java
261
262       curl
263
264       realplayer
265
266       Netscape 6, even though its called six, in the userAgent string has
267       version number 5. The nav6 and nav6up methods correctly handle this
268       quirk. The firefox text correctly detects the older-named versions of
269       the browser (Phoenix, Firebird)
270
271   browser_string()
272       Returns undef on failure.  Otherwise returns one of the following:
273
274       Firefox, Safari, Chrome, MSIE, etc
275
276       To see a complete list of possible browser strings, check the
277       browser_string() method in the source code.
278
279   gecko_version()
280       If a Gecko rendering engine is used (as in Mozilla or Firebird),
281       returns the version of the renderer (e.g. 1.3a, 1.7, 1.8) This might be
282       more useful than the particular browser name or version when correcting
283       for quirks in different versions of this rendering engine. If no Gecko
284       browser is being used, or the version number can't be detected, returns
285       undef.
286

Detecting Other Devices

288       The following methods are available, each returning a true or false
289       value.
290
291       android
292
293       audrey
294
295       avantgo
296
297       blackberry
298
299       iopener
300
301       iphone
302
303       ipod
304
305       ipad
306
307       palm
308
309       wap
310
311   mobile()
312       Returns true if the browser appears to belong to a handheld device.
313
314   robot()
315       Returns true if the user agent appears to be a robot, spider, crawler,
316       or other automated Web client.
317
318       The following additional methods are available, each returning a true
319       or false value. This is by no means a complete list of robots that
320       exist on the Web.
321
322       wget
323
324       getright
325
326       yahoo
327
328       altavista
329
330       lycos
331
332       infoseek
333
334       lwp
335
336       webcrawler
337
338       linkexchange
339
340       slurp
341
342       google
343
344       puf
345

AUTHOR

347       Lee Semel, lee@semel.net (Original Author)
348
349       Peter Walsham (co-maintainer)
350
351       Olaf Alders, "olaf at wundercounter.com" (co-maintainer)
352

ACKNOWLEDGEMENTS

354       Thanks to the following for their contributions:
355
356       Leonardo Herrera
357
358       Denis F. Latypoff
359
360       merlynkline
361
362       Simon Waters
363
364       Toni Cebrin
365
366       Florian Merges
367
368       david.hilton.p
369
370       Steve Purkis
371
372       Andrew McGregor
373
374       Robin Smidsrod
375
376       Richard Noble
377
378       Josh Ritter
379
380       Mike Clarke
381
382       Marc Sebastian Pelzer
383
384       Alexey Surikov
385
386       Maros Kollar
387
388       Jay Rifkin
389

TO DO

391       The _engine() method currently only handles Gecko.  It needs to be
392       expanded to handle other rendering engines.
393
394       POD coverage is also not 100%.
395
396       If you're able to help out with anything on the TO DO list, please do.
397       A great deal of the latest improvements have come from patches via RT
398       and GitHub pull requests. If you're able to submit changes via GitHub,
399       I'm generally able to get them into a new release fairly quickly.
400

SEE ALSO

402       "The Ultimate JavaScript Client Sniffer, Version 3.0",
403       http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html.
404
405       "Browser ID (User-Agent) Strings"
406       http://www.zytrax.com/tech/web/browser_ids.htm
407
408       perl(1), HTTP::Headers, HTTP::Headers::UserAgent.
409

SUPPORT

411       You can find documentation for this module with the perldoc command.
412
413           perldoc HTTP::BrowserDetect
414
415       You can also look for information at:
416
417       ·   GitHub Source Repository
418
419           http://github.com/oalders/http-browserdetect
420           <http://github.com/oalders/http-browserdetect>
421
422       ·   RT: CPAN's request tracker
423
424           http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTTP-BrowserDetect
425           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTTP-BrowserDetect>
426
427       ·   AnnoCPAN: Annotated CPAN documentation
428
429           http://annocpan.org/dist/HTTP-BrowserDetect
430           <http://annocpan.org/dist/HTTP-BrowserDetect>
431
432       ·   CPAN Ratings
433
434           http://cpanratings.perl.org/d/HTTP-BrowserDetect
435           <http://cpanratings.perl.org/d/HTTP-BrowserDetect>
436
437       ·   Search CPAN
438
439           http://search.cpan.org/dist/HTTP-BrowserDetect/
440           <http://search.cpan.org/dist/HTTP-BrowserDetect/>
441

BUGS AND LIMITATIONS

443       The biggest limitation at this point is the test suite, which really
444       needs to have many more UserAgent strings to test against.
445
446       Patches are certainly welcome, with many thanks to the many
447       contributions which have already been received. The preferred method of
448       patching would be to fork the GitHub repo and then send me a pull
449       requests, but plain old patch files are also welcome.
450
452       Copyright 1999-2010 Lee Semel. All rights reserved. This program is
453       free software; you can redistribute it and/or modify it under the same
454       terms as Perl itself.
455
456
457
458perl v5.12.0                      2010-05-05            HTTP::BrowserDetect(3)
Impressum