2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is KaiRo's userAgent detection.
17 * The Initial Developer of the Original Code is
18 * KaiRo - Robert Kaiser.
19 * Portions created by the Initial Developer are Copyright (C) 2003-2007
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s): Robert Kaiser <kairo@kairo.at>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 // userAgent PHP class
40 // get user agent and tell us what Browser is accessing
42 // function __construct([$ua_string])
43 // CONSTRUCTOR; reads UA string (or takes the optional given UA string) and gets info from that into our variables.
46 // the plain User Agent string
48 // the User Agent brand name
50 // the User Agent version
52 // bool: true if this agent is a bot
54 // array of static user agent data (static vars in functions are set for all objects of this class!)
56 // public function getBrand()
57 // returns the User Agent Brand Name
59 // public function getVersion()
60 // returns the User Agent version
62 // public function getAcceptLanguages()
63 // returns an associated array with the accepted languages of this UA
64 // keys are language codes, values are q factors (weights)
66 // public function getUAString()
67 // returns the full User Agent string
69 // public function getEngine()
70 // returns a string telling the detected rendering engine, null if we can't detect
71 // one of gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|unknown
73 // public function hasEngine($rnd_engine)
74 // returns true if the given rendering engine was detected
76 // public function getEngineVersion()
77 // returns a the version number for the rendering engine
78 // this may be the same as getVersion() for many engines, or null if we don't know
80 // public function getOS()
81 // returns a string telling the detected operating system, null if we can't detect
82 // might be very verbose, uses no abbreviations for most names
84 // public function getPlatform()
85 // returns a string telling the detected OS platform, null if we can't detect
86 // one of windows|linux|mac|solaris|unknown
88 // public function getLanguage() {
89 // returns a string telling the detected browser UI language, null if we can't detect
90 // should be an ISO code
92 // public function isBot()
93 // returns true if User Agent seems to be a bot
95 // *** functions that only return useable info for some agents ***
97 // public function getGeckoDate()
98 // returns the Gecko date for Gecko-based browsers, null for others
100 // public function getGeckoTime()
101 // returns the Gecko build date/time as a unix epoch time number for Gecko-based browsers, null for others
103 // *** functions for compat to older versions of this class ***
105 // public function isns()
106 // returns true if User Agent seems to be Netscape brand, false if not
107 // public function isns4()
108 // returns true if User Agent seems to be Netscape Communicator 4.x, false if not
109 // public function isie()
110 // returns true if User Agent seems to be a version of Internet Exploder, false if not
111 // public function geckobased()
112 // returns true if User Agent seems to be a Gecko-based browser, false if not
113 // public function geckodate()
114 // returns the Gecko date when it's a Gecko-based browser, 0 if not
115 // public function khtmlbased()
116 // returns true if User Agent seems to be a KHTML-based browser, false if not
118 // collection of some known User Agent Strings:
119 // *** see testbed/ua_list_raw.txt ***
120 // *** see also http://www.pgts.com.au/pgtsj/pgtsj0208c.html ***
125 private $bot = false;
126 private $uadata = array();
128 function __construct($ua_string = '') {
129 // *** constructor ***
130 if (strlen($ua_string)) {
131 $this->uastring = $ua_string;
134 // read raw UA string
135 $this->uastring = $_SERVER['HTTP_USER_AGENT'];
138 // get UA brand and version
139 $this->brand = 'Unknown'; $this->version = null;
140 // find reasonable defaults
141 if (preg_match('|([0-9a-zA-Z\.:()_ -]+)/(\d[0-9a-zA-Z\._+-]*)|', $this->uastring, $regs)) {
142 $this->brand = trim($regs[1]);
143 $this->version = $regs[2];
145 elseif (preg_match('|^([a-zA-Z\._ -]+)[_ -][vV]?(\d[0-9a-zA-Z\.+]*)|', $this->uastring, $regs)) {
146 $this->brand = trim($regs[1]);
147 $this->version = $regs[2];
149 elseif (preg_match('|^([0-9a-zA-Z\._ -]+)|', $this->uastring, $regs)) {
150 $this->brand = trim($regs[1]);
151 $this->version = null;
153 $this->bot = (strpos(strtolower($this->brand), 'bot') !== false)
154 || (strpos(strtolower($this->brand), 'crawler') !== false)
155 || (strpos(strtolower($this->brand), 'spider') !== false)
156 || (strpos(strtolower($this->brand), 'search') !== false)
157 || (strpos(strtolower($this->brand), 'seek') !== false);
159 // search for any real and/or special UAs
160 if (preg_match('|Netscape6/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
161 $this->brand = 'Netscape';
162 $this->version = $regs[1];
165 elseif (preg_match('|Netscape/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
166 $this->brand = 'Netscape';
167 $this->version = $regs[1];
170 elseif (preg_match('|Navigator/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
171 $this->brand = 'Netscape';
172 $this->version = $regs[1];
175 elseif (preg_match('|Chimera/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
176 $this->brand = 'Chimera';
177 $this->version = $regs[1];
180 elseif (preg_match('|Camino/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
181 $this->brand = 'Camino';
182 $this->version = $regs[1];
185 elseif (preg_match('|Phoenix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
186 $this->brand = 'Phoenix';
187 $this->version = $regs[1];
190 elseif (preg_match('|Mozilla Firebird/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
191 $this->brand = 'Mozilla Firebird';
192 $this->version = $regs[1];
195 elseif (preg_match('|Flock/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
196 $this->brand = 'Flock';
197 $this->version = $regs[1];
200 elseif (preg_match('|SeaMonkey/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
201 $this->brand = 'SeaMonkey';
202 $this->version = $regs[1];
205 elseif (preg_match('|Iceape/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
206 $this->brand = 'IceApe'; // Debian-rebranded SeaMonkey
207 $this->version = $regs[1];
210 elseif (preg_match('|Iceweasel/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
211 $this->brand = 'IceWeasel'; // Debian-rebranded Firefox
212 $this->version = $regs[1];
215 elseif (preg_match('|Icedove/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
216 $this->brand = 'IceDove'; // Debian-rebranded Thunderbird
217 $this->version = $regs[1];
220 elseif (preg_match('|BonEcho/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
221 $this->brand = 'Bon Echo'; // Firefox 2.0 code name
222 $this->version = $regs[1];
225 elseif (preg_match('|GranParadiso/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
226 $this->brand = 'Gran Paradiso'; // Firefox 3.0 code name
227 $this->version = $regs[1];
230 elseif (preg_match('|Shiretoko/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
231 $this->brand = 'Shiretoko'; // Firefox 3.5 code name
232 $this->version = $regs[1];
235 elseif (preg_match('|Namoroka/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
236 $this->brand = 'Namoroka'; // Firefox 3.6 code name
237 $this->version = $regs[1];
240 elseif (preg_match('|Lorentz/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
241 $this->brand = 'Lorentz'; // Firefox 3.6 (with OOPP) code name
242 $this->version = $regs[1];
245 elseif (preg_match('|Minefield/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
246 $this->brand = 'Minefield'; // Firefox development nightly code name
247 $this->version = $regs[1];
250 elseif (preg_match('|PmWFx/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
251 $this->brand = 'PmW-Firefox';
252 $this->version = $regs[1];
255 elseif (preg_match('|BeZillaBrowser/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
256 $this->brand = 'BeZillaBrowser';
257 $this->version = $regs[1];
260 elseif (preg_match('|Songbird/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
261 $this->brand = 'Songbird';
262 $this->version = $regs[1];
265 elseif (preg_match('|Lanikai/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
266 $this->brand = 'Lanikai'; // Thunderbird 3.1 code name
267 $this->version = $regs[1];
270 elseif (preg_match('|Shredder/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
271 $this->brand = 'Shredder'; // Thunderbird development nightly code name
272 $this->version = $regs[1];
275 elseif (preg_match('|prism/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
276 $this->brand = 'Prism';
277 $this->version = $regs[1];
280 elseif (preg_match('|Minimo/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
281 $this->brand = 'Minimo';
282 $this->version = $regs[1];
285 elseif (preg_match('|Fennec/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
286 $this->brand = 'Fennec'; // Firefox mobile code name
287 $this->version = $regs[1];
290 elseif (preg_match('|Galeon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
291 $this->brand = 'Galeon';
292 $this->version = $regs[1];
295 elseif (preg_match('|Epiphany/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
296 $this->brand = 'Epiphany';
297 $this->version = $regs[1];
300 elseif (preg_match('|K-Meleon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
301 $this->brand = 'K-Meleon';
302 $this->version = $regs[1];
305 elseif (preg_match('|AOL[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
306 $this->brand = 'AOL';
307 $this->version = $regs[1];
310 elseif (preg_match('|Tablet browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
311 $this->brand = 'microB';
312 $this->version = $regs[1];
315 elseif (preg_match('|Maemo Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
316 $this->brand = 'microB';
317 $this->version = $regs[1];
320 elseif (preg_match('|Opera\/([^\(]+) \(.*; Opera Mini; |', $this->uastring, $regs)) {
321 $this->brand = 'Opera Mini';
322 $this->version = $regs[1];
325 elseif (preg_match('/Opera\/[^\(]+ \(.*; Opera Mini\/([^;]+); /i', $this->uastring, $regs)) {
326 $this->brand = 'Opera Mini';
327 $this->version = $regs[1];
330 elseif (preg_match('|Opera[ /]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
331 $this->brand = 'Opera';
332 $this->version = $regs[1];
335 elseif (preg_match('|OmniWeb/([0-9a-zA-Z\.+-]+)|', $this->uastring, $regs)) {
336 $this->brand = 'OmniWeb';
337 $this->version = $regs[1];
340 elseif (preg_match('|Konqueror/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
341 $this->brand = 'Konqueror';
342 $this->version = $regs[1];
345 elseif (preg_match('|Shiira/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
346 $this->brand = 'Shiira';
347 $this->version = $regs[1];
350 elseif (preg_match('|Chrome/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
351 $this->brand = 'Chrome';
352 $this->version = $regs[1];
355 elseif (preg_match('|NokiaBrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
356 $this->brand = 'NokiaBrowser';
357 $this->version = $regs[1];
360 elseif (preg_match('|Safari/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
361 $this->brand = 'Safari';
362 if (preg_match('|Version/([0-9a-zA-Z\.+]+)|', $this->uastring, $vregs)) {
363 $this->version = $vregs[1];
366 $this->version = '('.$regs[1].')';
370 elseif (preg_match('|AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
371 $this->brand = 'AppleWebKit';
372 $this->version = $regs[1];
375 elseif (preg_match('|Spinn3r ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
376 $this->brand = 'Spinn3r';
377 $this->version = $regs[1];
380 elseif (preg_match('|Butterfly/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
381 $this->brand = 'Butterfly';
382 $this->version = $regs[1];
385 elseif (preg_match('|Googlebot/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
386 $this->brand = 'Googlebot';
387 $this->version = $regs[1];
390 elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
391 $this->brand = 'Firefox';
392 $this->version = $regs[1];
395 elseif (preg_match('|Thunderbird/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
396 $this->brand = 'Thunderbird';
397 $this->version = $regs[1];
400 elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
401 strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
402 $this->brand = 'Mozilla';
403 $this->version = $regs[1];
406 elseif (preg_match('|m([0-9]+)\)|', $this->uastring, $regs) &&
407 strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
408 $this->brand = 'Mozilla';
409 $this->version = 'M'.$regs[1];
412 elseif (preg_match('|Baiduspider|i', $this->uastring)) {
413 $this->brand = 'BaiDuSpider';
414 $this->version = null;
417 elseif (preg_match('|YodaoBot-Mobile/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
418 $this->brand = 'YodaoBot-Mobile';
419 $this->version = $regs[1];
422 elseif (preg_match('|Googlebot-Mobile/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
423 $this->brand = 'Googlebot-Mobile';
424 $this->version = $regs[1];
427 elseif (preg_match('|FASTMobileCrawl/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
428 $this->brand = 'FASTMobileCrawl';
429 $this->version = $regs[1];
432 elseif (preg_match('|MSFrontPage/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
433 $this->brand = 'Microsoft FrontPage';
434 $this->version = $regs[1];
437 elseif (preg_match('|iCab[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
438 $this->brand = 'iCab';
439 $this->version = $regs[1];
442 elseif (preg_match('|IBrowse[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
443 $this->brand = 'IBrowse';
444 $this->version = $regs[1];
447 elseif (preg_match('|ICEbrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
448 $this->brand = 'ICEbrowser';
449 $this->version = $regs[1];
452 elseif (preg_match('|ICE Browser/v([0-9a-zA-Z\._+]+)|', $this->uastring, $regs)) {
453 $this->brand = 'ICEbrowser';
454 $this->version = str_replace('_', '.', $regs[1]);
457 elseif (preg_match('|NetPositive/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
458 $this->brand = 'NetPositive';
459 $this->version = $regs[1];
462 elseif (preg_match('|WebPro/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
463 $this->brand = 'WebPro (Novarra)';
464 $this->version = $regs[1];
467 elseif (preg_match('|; OffByOne;|', $this->uastring, $regs)) {
468 $this->brand = 'Off By One';
469 $this->version = null;
472 elseif (preg_match('|PSP \(PlayStation Portable\); ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
473 $this->brand = 'PlayStation Portable';
474 $this->version = $regs[1];
477 elseif (preg_match('|PLAYSTATION 3; ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
478 $this->brand = 'PlayStation 3';
479 $this->version = $regs[1];
482 elseif (preg_match('|NetFront/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
483 $this->brand = 'NetFront';
484 $this->version = $regs[1];
487 elseif (preg_match('|UP.Browser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
488 $this->brand = 'UP.Browser';
489 $this->version = $regs[1];
492 elseif (preg_match('|UP.Link/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
493 $this->brand = 'UP.Link';
494 $this->version = $regs[1];
497 elseif (preg_match('|AU-MIC-([0-9A-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
498 $this->brand = 'Obigo';
499 $this->version = $regs[1];
502 elseif (preg_match('|Browser/Obigo-([0-9A-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
503 $this->brand = 'Obigo';
504 $this->version = $regs[1];
507 elseif (preg_match('|Nokia([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
508 $this->brand = 'Nokia';
509 $this->version = $regs[1];
512 elseif (preg_match('|SonyEricsson([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
513 $this->brand = 'SonyEricsson';
514 $this->version = $regs[1];
517 elseif (preg_match('|SIE-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
518 $this->brand = 'Siemens';
519 $this->version = $regs[1];
522 elseif (preg_match('|MOT-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
523 $this->brand = 'Motorola';
524 $this->version = $regs[1];
527 elseif (preg_match('|IXI/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
528 $this->brand = 'IXI';
529 $this->version = $regs[1];
532 elseif (preg_match('|NewsFox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
533 $this->brand = 'NewsFox';
534 $this->version = $regs[1];
537 elseif (preg_match('|rdfbot/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
538 $this->brand = 'rdfbot';
539 $this->version = $regs[1];
542 elseif (preg_match('|IBM-WebExplorer-DLL/v([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
543 $this->brand = 'WebExplorer';
544 $this->version = $regs[1];
547 elseif (preg_match('|ELinks \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
548 $this->brand = 'ELinks';
549 $this->version = $regs[1];
552 elseif (preg_match('|Links \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
553 $this->brand = 'Links';
554 $this->version = $regs[1];
557 elseif (preg_match('|WinHttp.WinHttpRequest.([0-9\.]+)|i', $this->uastring, $regs)) {
558 $this->brand = 'WinHttpRequest';
559 $this->version = $regs[1];
562 elseif (preg_match('|alpha[/ ]06; AmigaOS|i', $this->uastring, $regs)) {
563 $this->brand = 'Alpha 06';
564 $this->version = null;
567 elseif (preg_match('|; arexx[\);]|i', $this->uastring, $regs)) {
568 $this->brand = 'ARexx';
569 $this->version = null;
572 elseif (preg_match('|; Voyager; AmigaOS[\);]|i', $this->uastring, $regs)) {
573 $this->brand = 'AmigaVoyager';
574 $this->version = null;
577 elseif (preg_match('|AWEB ([0-9a-zA-Z\.+ ]+)|', $this->uastring, $regs)) {
578 $this->brand = 'AWEB';
579 $this->version = $regs[1];
582 elseif (preg_match('|X ([0-9a-zA-Z\.+ ]+); Commodore 64|', $this->uastring, $regs)) {
584 $this->version = $regs[1];
587 elseif (preg_match('|DB Browse ([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
588 $this->brand = 'DB Browse';
589 $this->version = $regs[1];
592 elseif (preg_match('|ZyBorg/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
593 $this->brand = 'ZyBorg';
594 $this->version = $regs[1];
597 elseif (preg_match('|Ask Jeeves/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
598 $this->brand = 'Ask Jeeves';
599 $this->version = $regs[1];
602 elseif (preg_match('|heritrix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
603 $this->brand = 'Heritrix';
604 $this->version = $regs[1];
607 elseif (preg_match('|heritrix([0-9a-zA-Z\.+-]+)|', $this->uastring, $regs)) {
608 $this->brand = 'Heritrix';
609 $this->version = str_replace('-', '.', $regs[1]);
612 elseif (preg_match('|SBSearch/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
613 $this->brand = 'SBSearch';
614 $this->version = $regs[1];
617 elseif (preg_match('|Powermarks/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
618 $this->brand = 'Powermarks';
619 $this->version = $regs[1];
622 elseif (preg_match('|TopBlogsInfo/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
623 $this->brand = 'TopBlogsInfo';
624 $this->version = $regs[1];
627 elseif (preg_match('|picmole/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
628 $this->brand = 'picmole';
629 $this->version = $regs[1];
632 elseif (preg_match('|([0-9a-zA-Z\._+-]+bot)/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
633 $this->brand = $regs[1];
634 $this->version = $regs[2];
637 elseif (preg_match('|VoilaBot ((BETA )?[0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
638 $this->brand = 'VoilaBot';
639 $this->version = $regs[1];
642 elseif (preg_match('|Slurp|', $this->uastring, $regs)) {
643 $this->brand = 'Slurp';
644 $this->version = null;
647 elseif (preg_match('|Check&Get ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
648 $this->brand = 'Check&Get';
649 $this->version = $regs[1];
652 elseif (preg_match('|WebCapture ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
653 $this->brand = 'WebCapture';
654 $this->version = $regs[1];
657 elseif (preg_match('|WebMon ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
658 $this->brand = 'WebMon';
659 $this->version = $regs[1];
662 elseif (preg_match('|Gulper Web Bot ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
663 $this->brand = 'Gulper Web Bot';
664 $this->version = $regs[1];
667 elseif (preg_match('|HTTrack ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
668 $this->brand = 'HTTrack';
669 $this->version = $regs[1];
672 elseif (preg_match('|Advista Crawler ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
673 $this->brand = 'HTTrack';
674 $this->version = $regs[1];
677 elseif (preg_match('|Seznam screenshot-generator ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
678 $this->brand = 'Seznam screenshot-generator';
679 $this->version = $regs[1];
682 elseif (preg_match('|Yahoo! SearchMonkey ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
683 $this->brand = 'Yahoo! SearchMonkey';
684 $this->version = $regs[1];
687 elseif (preg_match('|Yahoo Pipes ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
688 $this->brand = 'Yahoo! Pipes';
689 $this->version = $regs[1];
692 elseif (preg_match('|Firebat ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
693 $this->brand = 'Firebat';
694 $this->version = $regs[1];
697 elseif (preg_match('|Twiceler-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
698 $this->brand = 'Twiceler';
699 $this->version = $regs[1];
702 elseif (preg_match('|Nu_?tch-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
703 $this->brand = 'Nutch';
704 $this->version = $regs[1];
707 elseif (preg_match('|Microsoft URL Control - ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
708 $this->brand = 'Microsoft URL Control';
709 $this->version = $regs[1];
712 elseif (preg_match('|([0-9a-zA-Z\.+]+)_AC-Plug|', $this->uastring, $regs)) {
713 $this->brand = 'AC-Plug';
714 $this->version = $regs[1];
717 elseif (preg_match('|^Internet Explorer 5.5|', $this->uastring)) {
718 $this->brand = 'Unknown bot (IE5.5)';
719 $this->version = null;
722 elseif (preg_match('|^Mozilla[\s ]*$|', $this->uastring)) {
723 $this->brand = 'Unknown bot (Mozilla)';
724 $this->version = null;
727 elseif (preg_match('|ICCrawler|i', $this->uastring, $regs)) {
728 $this->brand = 'ICCrawler';
729 $this->version = null;
732 elseif (preg_match('|KaloogaBot|', $this->uastring, $regs)) {
733 $this->brand = 'KaloogaBot';
734 $this->version = null;
737 elseif (preg_match('|ScoutJet|', $this->uastring, $regs)) {
738 $this->brand = 'ScoutJet';
739 $this->version = null;
742 elseif (preg_match('|http://www.livedir.net|', $this->uastring, $regs)) {
743 $this->brand = 'livedir.net';
744 $this->version = null;
747 elseif (preg_match('|WebClipping.com|', $this->uastring, $regs)) {
748 $this->brand = 'WebClipping.com';
749 $this->version = null;
752 elseif (preg_match('|newstin.com|', $this->uastring, $regs)) {
753 $this->brand = 'newstin.com';
754 $this->version = null;
757 elseif (preg_match('|http://www.almaden.ibm.com/cs/crawler|', $this->uastring)) {
758 $this->brand = 'almaden crawler';
759 $this->version = null;
762 elseif (preg_match('|B-l-i-t-z-B-O-T|', $this->uastring) ||
763 preg_match('|B l i t z B O T @ t r i c u s . n e t|', $this->uastring)) {
764 $this->brand = 'BlitzBOT';
765 $this->version = null;
768 elseif (preg_match('|Really Gmane.org\'s favicon grabber|', $this->uastring)) {
769 $this->brand = 'Really Gmane.org\'s favicon grabber';
770 $this->version = null;
773 elseif (preg_match('|Girafabot|', $this->uastring)) {
774 $this->brand = 'Girafabot';
775 $this->version = null;
778 elseif (preg_match('|Arachmo|', $this->uastring)) {
779 $this->brand = 'Arachmo';
780 $this->version = null;
783 elseif (preg_match('|OsO|', $this->uastring)) {
784 $this->brand = 'OsO';
785 $this->version = null;
788 elseif (preg_match('|Yoono|', $this->uastring)) {
789 $this->brand = 'Yoono';
790 $this->version = null;
793 elseif (preg_match('|efp@gmx.net|', $this->uastring)) {
794 $this->brand = 'efp';
795 $this->version = null;
798 elseif (preg_match('|Indy Library|', $this->uastring)) {
799 $this->brand = 'Indy Library';
800 $this->version = null;
803 elseif (preg_match('|Linkman|', $this->uastring)) {
804 $this->brand = 'Linkman';
805 $this->version = null;
808 elseif (preg_match('|Sage|', $this->uastring, $regs)) {
809 $this->brand = 'Sage';
810 $this->version = null;
813 elseif (preg_match('|Google Desktop|', $this->uastring)) {
814 $this->brand = 'Google Desktop';
815 $this->version = null;
818 elseif (preg_match('|^Firefly|', $this->uastring)) {
819 // comes here with correct value but would be detected as MSIE
821 elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
822 $this->brand = 'Steganos Internet Anonym';
823 $this->version = $regs[1];
826 elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
827 $this->brand = 'Steganos Internet Anonym';
828 $this->version = $regs[1];
831 elseif (preg_match('|BorderManager ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
832 $this->brand = 'BorderManager';
833 $this->version = $regs[1];
836 elseif (preg_match('|WebWasher ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
837 $this->brand = 'WebWasher';
838 $this->version = $regs[1];
841 elseif (preg_match('|SaferSurf|', $this->uastring, $regs)) {
842 $this->brand = 'SaferSurf';
843 $this->version = null;
846 elseif (preg_match('|Avant Browser[^/]|', $this->uastring)) {
847 $this->brand = 'Avant Browser';
848 $this->version = null;
851 elseif (preg_match('|Browser[^/]+(http://www.avantbrowser.com)|', $this->uastring)) {
852 $this->brand = 'Avant Browser';
853 $this->version = null;
856 elseif (preg_match('|Maxthon|', $this->uastring)) {
857 $this->brand = 'Maxthon';
858 $this->version = null;
861 elseif (preg_match('|MyIE2|', $this->uastring)) {
862 $this->brand = 'MyIE2';
863 $this->version = null;
866 elseif (preg_match('|Crazy Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
867 $this->brand = 'Crazy Browser';
868 $this->version = $regs[1];
871 elseif (preg_match('|AvantGo ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
872 $this->brand = 'AvantGo';
873 $this->version = $regs[1];
876 elseif (preg_match('|MSN ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
877 $this->brand = 'MSN';
878 $this->version = $regs[1];
881 elseif (preg_match('|America Online Browser [0-9a-zA-Z\.+]+; rev([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
882 $this->brand = 'AOL Browser';
883 $this->version = $regs[1];
886 elseif (preg_match('|MS FrontPage ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
887 $this->brand = 'Microsoft FrontPage';
888 $this->version = $regs[1];
891 elseif (preg_match('|Microsoft Internet Explorer/4.0b1|', $this->uastring, $regs)) {
892 $this->brand = 'Microsoft Internet Explorer';
893 $this->version = '1.0';
896 elseif (preg_match('|MSIE 7\.0.+Trident/4.0|', $this->uastring, $regs)) {
897 $this->brand = 'Microsoft Internet Explorer';
898 $this->version = "8.0";
901 elseif (preg_match('|MSIE 7\.0.+Trident/5.0|', $this->uastring, $regs)) {
902 $this->brand = 'Microsoft Internet Explorer';
903 $this->version = "9.0";
906 elseif (preg_match('|MSIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
907 $this->brand = 'Microsoft Internet Explorer';
908 $this->version = $regs[1];
911 elseif (preg_match('|MSPIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
912 $this->brand = 'Microsoft Pocket Internet Explorer';
913 $this->version = $regs[1];
916 elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
917 (strpos($this->uastring, 'compatible') === false) && (strpos($this->uastring, 'Gecko/') === false) &&
918 (intval($regs[1]) < 5)) {
919 $this->brand = 'Netscape';
920 $this->version = $regs[1];
921 if (intval($this->version) == 4) { $this->brand .= ' Communicator'; }
924 elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
925 $this->brand = (strpos($this->uastring, 'compatible') !== false)?'Mozilla-compatible (unknown)':'Mozilla (unknown)';
926 $this->version = null;
930 $botArray = array('Scooter','Spinne','Vagabondo','Firefly','Scrubby','NG','Pompos','Szukacz','Schmozilla','42_HAL',
931 'NetResearchServer','LinkWalker','Zeus','W3C_Validator','ZyBorg','Ask Jeeves','ia_archiver',
932 'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','search.ch',
933 'appie','larbin','NutchCVS','Webchat','Mediapartners-Google','sitecheck.internetseer.com',
934 'FavOrg','findlinks','DataCha0s','ichiro','Francis','CoralWebPrx','DoCoMo','Ocelli','Sogou Video',
935 'Yandex','Yeti','Austronaut-URL-Checker');
937 if (in_array($this->brand, $botArray)) {
942 public function getBrand() { return $this->brand; }
943 public function getVersion() { return $this->version; }
945 public function getAcceptLanguages() {
946 if (!isset($this->uadata['accept-languages'])) {
947 $headers = getAllHeaders();
948 $accLcomp = explode(',', $headers['Accept-Language']);
950 foreach ($accLcomp as $lcomp) {
951 if (strlen($lcomp)) {
952 $ldef = explode(';', $lcomp);
953 $accLang[$ldef[0]] = (float)((strpos(@$ldef[1],'q=')===0)?substr($ldef[1],2):1);
956 $this->uadata['accept-languages'] = $accLang;
958 return $this->uadata['accept-languages'];
961 public function getUAString() { return $this->uastring; }
963 public function getEngine() {
964 // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|netfront|unknown
965 if (!isset($this->uadata['engine'])) {
966 $this->uadata['engine'] = 'unknown';
967 $this->uadata['geckodate'] = null;
969 if (preg_match('|Gecko/([0-9]+)|', $this->uastring, $regs) && (strpos($this->brand, 'Opera') === false)) {
970 $this->uadata['engine'] = 'gecko';
971 $this->uadata['geckodate'] = $regs[1];
973 elseif ((strpos($this->brand, 'Internet Explorer') !== false) || (strpos($this->brand, 'FrontPage') !== false)) {
974 if ((strpos(strtolower($this->uastring), 'mac') !== false) && (intval($this->getVersion()) >= 5)) {
975 $this->uadata['engine'] = 'tasman';
978 $this->uadata['engine'] = 'trident';
981 elseif (preg_match('|WebKit/([0-9]+)|', $this->uastring, $regs)) {
982 $this->uadata['engine'] = 'webkit';
984 elseif ((strpos($this->brand, 'Konqueror') !== false) || (strpos($this->brand, 'OmniWeb') !== false)) {
985 $this->uadata['engine'] = 'khtml';
987 elseif (strpos($this->brand, 'Netscape') !== false) {
988 // non-Gecko Netscape browsers
989 if (intval($this->version) <= 4) {
990 $this->uadata['engine'] = 'nscp';
992 elseif (strpos($this->uastring, 'MSIE') !== false) {
993 $this->uadata['engine'] = 'trident';
996 elseif (strpos($this->brand, 'Opera') !== false) {
997 $this->uadata['engine'] = 'presto';
999 elseif (strpos($this->brand, 'Dillo') !== false) {
1000 $this->uadata['engine'] = 'gzilla';
1002 elseif ((strpos($this->brand, 'ELinks') !== false) || (strpos($this->brand, 'Links') !== false)) {
1003 $this->uadata['engine'] = 'links';
1005 elseif ((strpos($this->brand, 'Lynx') !== false)) {
1006 $this->uadata['engine'] = 'lynx';
1008 elseif ((strpos($this->brand, 'ICEbrowser') !== false) || (strpos($this->brand, 'ICE Browser') !== false)) {
1009 $this->uadata['engine'] = 'icestorm';
1011 elseif ((strpos($this->brand, 'PlayStation') !== false) || (strpos($this->brand, 'NetFront') !== false)) {
1012 $this->uadata['engine'] = 'netfront';
1014 elseif ((strpos($this->brand, 'Avant') !== false) || (strpos($this->brand, 'Crazy Browser') !== false) ||
1015 (strpos($this->brand, 'AOL') !== false) || (strpos($this->brand, 'MSN') !== false) ||
1016 (strpos($this->brand, 'MyIE2') !== false) || (strpos($this->brand, 'Maxthon') !== false)) {
1017 $this->uadata['engine'] = 'trident';
1019 elseif (strpos($this->brand, 'Galeon') !== false) {
1020 $this->uadata['engine'] = 'gecko';
1022 elseif (strpos($this->brand, 'WebPro') !== false) {
1023 $this->uadata['engine'] = 'nscp';
1027 return $this->uadata['engine'];
1030 public function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); }
1032 public function getEngineVersion() {
1033 if (!isset($this->uadata['eng_version'])) {
1034 $this->uadata['eng_version'] = null;
1035 // getOS() should get the date for us
1038 return $this->uadata['eng_version'];
1041 public function getOS() {
1042 if (!isset($this->uadata['os'])) {
1043 $this->uadata['os'] = null;
1045 if ($this->hasEngine('gecko')) {
1046 if (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1047 $this->uadata['os'] = $regs[2].' ('.$regs[3].')';
1048 $this->uadata['lang'] = (strpos($regs[4],'chrome://')===false)?$regs[4]:null;
1049 $this->uadata['eng_version'] = $regs[5];
1051 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1052 $this->uadata['os'] = $regs[2];
1053 $this->uadata['lang'] = (strpos($regs[3],'chrome://')===false)?$regs[3]:null;
1054 $this->uadata['eng_version'] = $regs[4];
1056 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1057 $this->uadata['os'] = $regs[2];
1058 $this->uadata['lang'] = null;
1059 $this->uadata['eng_version'] = $regs[3];
1061 elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); x64; rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1062 $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1063 $this->uadata['lang'] = null;
1064 $this->uadata['eng_version'] = $regs[3];
1066 elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1067 $this->uadata['os'] = $regs[2];
1068 $this->uadata['lang'] = (strpos($regs[3],'chrome://')===false)?$regs[3]:null;
1069 $this->uadata['eng_version'] = $regs[4];
1071 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
1072 $this->uadata['os'] = $regs[2];
1073 $this->uadata['lang'] = $regs[3];
1074 $this->uadata['eng_version'] = 'M'.$regs[4];
1076 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
1077 $this->uadata['os'] = $regs[1];
1078 $this->uadata['lang'] = $regs[2];
1079 $this->uadata['eng_version'] = 'M'.$regs[3];
1081 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1082 $this->uadata['os'] = $regs[2];
1083 $this->uadata['lang'] = $regs[3];
1084 $this->uadata['eng_version'] = null;
1086 elseif (preg_match('|Mozilla/5.0 \(([^;]+); (WOW64); rv:([^\);]+)\)|', $this->uastring, $regs)) {
1087 $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1088 $this->uadata['lang'] = null;
1089 $this->uadata['eng_version'] = $regs[3];
1091 elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) {
1092 if ((strpos($regs[2], 'Linux') !== false) && ($regs[1] != 'X11')) {
1093 $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1096 $this->uadata['os'] = $regs[2];
1098 $this->uadata['lang'] = null;
1099 $this->uadata['eng_version'] = $regs[3];
1101 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^\);]+)\)|', $this->uastring, $regs)) {
1102 $this->uadata['os'] = $regs[2];
1103 $this->uadata['lang'] = null;
1104 $this->uadata['eng_version'] = null;
1106 elseif (preg_match('|Mozilla/5.0 \(([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) {
1107 $this->uadata['os'] = $regs[1];
1108 $this->uadata['lang'] = null;
1109 $this->uadata['eng_version'] = $regs[2];
1111 elseif (preg_match('|Mozilla/5.0 Galeon/[^\(]+ \(([^;]+); ([^;]+);[^\)]+\)|', $this->uastring, $regs)) {
1112 $this->uadata['os'] = $regs[2];
1113 $this->uadata['lang'] = null;
1114 $this->uadata['eng_version'] = null;
1116 elseif (preg_match('|Debian/|', $this->uastring, $regs)) {
1117 $this->uadata['os'] = 'Debian Linux';
1118 $this->uadata['lang'] = null;
1119 $this->uadata['eng_version'] = null;
1122 elseif ($this->hasEngine('trident') || $this->hasEngine('tasman')) {
1123 if (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE [^;]+[^\)]*; ?((?:Mac|Win)[^;]+); ?(Win64|WOW64)[^\)]*Trident\/([^;\)]+)[^\)]*\)/i', $this->uastring, $regs)) {
1124 $this->uadata['eng_version'] = $regs[3];
1125 $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1126 $this->uadata['lang'] = null;
1128 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE [^;]+[^\)]*; ?((?:Mac|Win)[^;]+); ?[^\)]*Trident\/([^;\)]+)[^\)]*\)/i', $this->uastring, $regs)) {
1129 $this->uadata['eng_version'] = $regs[2];
1130 $this->uadata['os'] = $regs[1];
1131 $this->uadata['lang'] = null;
1133 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSP?IE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+); ?(Win64|WOW64)[^\)]*\)/i', $this->uastring, $regs)) {
1134 $this->uadata['eng_version'] = (strpos($this->uastring,'MSPIE')!==false)?null:"ie".$regs[1];
1135 $this->uadata['os'] = $regs[2].' ('.$regs[3].')';
1136 $this->uadata['lang'] = null;
1138 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSP?IE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
1139 $this->uadata['eng_version'] = (strpos($this->uastring,'MSPIE')!==false)?null:"ie".$regs[1];
1140 $this->uadata['os'] = $regs[2];
1141 $this->uadata['lang'] = null;
1143 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE ([^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
1144 $this->uadata['eng_version'] = "ie".$regs[1];
1145 $this->uadata['os'] = null;
1146 $this->uadata['lang'] = null;
1148 elseif (preg_match('/Microsoft Internet Explorer\/[^\s]+ \(((?:Mac|Win)[^;\)]+)\)/i', $this->uastring, $regs)) {
1149 $this->uadata['eng_version'] = "ie".$this->getVersion();
1150 $this->uadata['os'] = $regs[1];
1151 $this->uadata['lang'] = null;
1153 elseif (preg_match('/Microsoft Pocket Internet Explorer\/[^\s]+/i', $this->uastring, $regs)) {
1154 $this->uadata['eng_version'] = null;
1155 $this->uadata['os'] = 'Windows CE';
1156 $this->uadata['lang'] = null;
1159 elseif ($this->hasEngine('khtml')) {
1160 if (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^;]+); ([^;]+); ([^;]+); ([^\);]+)\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
1161 $this->uadata['eng_version'] = strlen($regs[6])?$regs[6]:$regs[1];
1162 $this->uadata['os'] = $regs[2];
1163 $this->uadata['lang'] = $regs[5];
1165 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^\);]+)[^\)]*\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
1166 $this->uadata['eng_version'] = strlen($regs[3])?$regs[3]:$regs[1];
1167 $this->uadata['os'] = $regs[2];
1168 $this->uadata['lang'] = null;
1170 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; [^;]+; ([^\);]+)\)/i', $this->uastring, $regs)) {
1171 $this->uadata['os'] = $regs[1];
1172 $this->uadata['lang'] = null;
1173 $this->uadata['eng_version'] = null;
1176 elseif ($this->hasEngine('webkit')) {
1177 if (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^;]+); ([^;]+); ([^\);]+)\) AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1178 $this->uadata['os'] = $regs[2];
1179 $this->uadata['lang'] = $regs[3];
1180 $this->uadata['eng_version'] = $regs[5];
1182 elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^;]+); ([^\);]+)\) AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1183 if (strpos($regs[3], '/') !== false) {
1184 $this->uadata['os'] = $regs[1];
1185 $this->uadata['lang'] = null;
1188 $this->uadata['os'] = $regs[2];
1189 $this->uadata['lang'] = $regs[3];
1191 $this->uadata['eng_version'] = $regs[4];
1193 elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^\);]+)\) AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1194 $this->uadata['os'] = $regs[1];
1195 $this->uadata['lang'] = $regs[2];
1196 $this->uadata['eng_version'] = $regs[3];
1198 elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^\);]+)\) AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1199 if (($regs[1] == 'X11') || ($regs[1] == 'Macintosh')) {
1200 $this->uadata['os'] = $regs[2];
1203 $this->uadata['os'] = $regs[1];
1204 if ($regs[2] == 'NokiaN9') {
1205 $this->uadata['os'] .= ' Harmattan';
1208 $this->uadata['lang'] = null;
1209 $this->uadata['eng_version'] = $regs[3];
1211 elseif (preg_match('|Mozilla/5.0 \(([^\);]+)\) AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1212 $this->uadata['os'] = $regs[1];
1213 $this->uadata['lang'] = null;
1214 $this->uadata['eng_version'] = $regs[2];
1216 elseif (preg_match('|Midori/[^\(]+ \((?:X11; )?([^;]+); U; ([^\)]+)\) WebKit/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
1217 $this->uadata['os'] = $regs[1];
1218 $this->uadata['lang'] = $regs[2];
1219 $this->uadata['eng_version'] = $regs[3];
1222 elseif ($this->hasEngine('presto')) {
1224 if (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+)[^\)]+\) +\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
1225 $this->uadata['eng_version'] = $this->getVersion();
1226 $this->uadata['os'] = $regs[1];
1227 $this->uadata['lang'] = $regs[2];
1229 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;\)]+)[^\)]*\) Opera [^ ]+\s+\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
1230 $this->uadata['eng_version'] = $this->getVersion();
1231 $this->uadata['os'] = $regs[1];
1232 $this->uadata['lang'] = $regs[2];
1234 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+\) Opera [^ ]+\s+\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
1235 $this->uadata['eng_version'] = $this->getVersion();
1236 $this->uadata['os'] = $regs[1];
1237 $this->uadata['lang'] = $regs[2];
1240 elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini; ([a-z_-]+); /i', $this->uastring, $regs)) {
1241 $this->uadata['eng_version'] = null;
1242 $this->uadata['os'] = $regs[2];
1243 $this->uadata['lang'] = $regs[3];
1245 elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini\/[^;]+; ([a-z_-]+); /i', $this->uastring, $regs)) {
1246 $this->uadata['eng_version'] = $regs[1];
1247 $this->uadata['os'] = $regs[2];
1248 $this->uadata['lang'] = $regs[3];
1251 elseif (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+); [^\)]+; ([a-z_-]+)\)/i', $this->uastring, $regs)) {
1252 $this->uadata['eng_version'] = $this->getVersion();
1253 $this->uadata['os'] = $regs[1];
1254 $this->uadata['lang'] = $regs[2];
1256 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;]+); ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
1257 $this->uadata['eng_version'] = $this->getVersion();
1258 $this->uadata['os'] = $regs[1];
1259 $this->uadata['lang'] = $regs[2];
1261 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
1262 $this->uadata['eng_version'] = $this->getVersion();
1263 $this->uadata['os'] = $regs[1];
1264 $this->uadata['lang'] = $regs[2];
1266 // Opera 9 Firefox-spoofing
1267 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+); rv:([^\);]+)\) Gecko\/\d+ Firefox\/[0-9a-zA-Z\.+]+ Opera [^ ]+/i', $this->uastring, $regs)) {
1268 $this->uadata['eng_version'] = $this->getVersion();
1269 $this->uadata['os'] = $regs[1];
1270 $this->uadata['lang'] = $regs[2];
1273 elseif ($this->hasEngine('nscp')) {
1274 if (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(X11; [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
1275 $this->uadata['eng_version'] = $regs[1];
1276 $this->uadata['os'] = $regs[3];
1277 $this->uadata['lang'] = $regs[2];
1279 elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
1280 $this->uadata['eng_version'] = $regs[1];
1281 $this->uadata['os'] = $regs[3];
1282 $this->uadata['lang'] = $regs[2];
1284 elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+)[^\(]+\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
1285 $this->uadata['eng_version'] = $regs[1];
1286 $this->uadata['os'] = $regs[2];
1287 $this->uadata['lang'] = null;
1290 elseif ($this->hasEngine('gzilla')) {
1291 $this->uadata['eng_version'] = $this->getVersion();
1292 $this->uadata['os'] = null;
1293 $this->uadata['lang'] = null;
1295 elseif ($this->hasEngine('links')) {
1296 if (preg_match('/E?Links[^\(]+\([^;]+; ([^;]+)[^\)]+\)/i', $this->uastring, $regs)) {
1297 $this->uadata['eng_version'] = null;
1298 $this->uadata['os'] = $regs[1];
1299 $this->uadata['lang'] = null;
1302 elseif ($this->hasEngine('lynx')) {
1303 $this->uadata['eng_version'] = $this->getVersion();
1304 $this->uadata['os'] = null;
1305 $this->uadata['lang'] = null;
1307 elseif ($this->hasEngine('icestorm')) {
1308 if (preg_match('/ICE Browser\/v?([0-9a-zA-Z\._+]+) \(Java [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
1309 $this->uadata['eng_version'] = str_replace('_', '.', $regs[1]);
1310 $this->uadata['os'] = $regs[2];
1311 $this->uadata['lang'] = null;
1313 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\).* ICEbrowser\/([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) {
1314 $this->uadata['eng_version'] = $regs[3];
1315 $this->uadata['os'] = $regs[1];
1316 $this->uadata['lang'] = $regs[2];
1320 $this->uadata['eng_version'] = null;
1321 $this->uadata['lang'] = null;
1322 if (preg_match('/AmigaOS/i', $this->uastring, $regs)) {
1323 $this->uadata['os'] = 'AmigaOS';
1325 if (preg_match('/Commodore 64/i', $this->uastring, $regs)) {
1326 $this->uadata['os'] = 'Commodore 64';
1328 elseif (preg_match('/curl\/[^\(]+\(([^\);]+)/i', $this->uastring, $regs)) {
1329 $this->uadata['os'] = $regs[1];
1331 elseif (preg_match('/NCSA[_ ]Mosaic\/[^\(]+\((?:.*;)?([^\);]+)/i', $this->uastring, $regs)) {
1332 $this->uadata['os'] = trim($regs[1]);
1334 elseif (preg_match('/iCab.*(Mac[^\);]+).*?\)/i', $this->uastring, $regs)) {
1335 $this->uadata['os'] = trim($regs[1]);
1337 elseif (preg_match('/SymbianOS\/([^ ]+)/i', $this->uastring, $regs)) {
1338 $this->uadata['os'] = 'SymbianOS '.$regs[1];
1341 if ($this->uadata['os'] == 'Win 9x 4.90') { $this->uadata['os'] = 'Windows ME'; }
1342 elseif ($this->uadata['os'] == 'WinNT4.0') { $this->uadata['os'] = 'Windows NT 4.0'; }
1343 elseif ($this->uadata['os'] == 'Windows NT 5.0') { $this->uadata['os'] = 'Windows 2000'; }
1344 elseif ($this->uadata['os'] == 'Windows NT 5.1') { $this->uadata['os'] = 'Windows XP'; }
1345 elseif ($this->uadata['os'] == 'Windows NT 5.1 (Win64)') { $this->uadata['os'] = 'Windows XP (64bit)'; }
1346 elseif ($this->uadata['os'] == 'Windows NT 5.1 (WOW64)') { $this->uadata['os'] = 'Windows XP (64bit)'; }
1347 elseif ($this->uadata['os'] == 'Windows NT 5.2') { $this->uadata['os'] = 'Windows 2003'; }
1348 elseif ($this->uadata['os'] == 'Windows NT 5.2 x64') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1349 elseif ($this->uadata['os'] == 'Windows NT 5.2 (Win64)') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1350 elseif ($this->uadata['os'] == 'Windows NT 5.2 (WOW64)') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1351 elseif ($this->uadata['os'] == 'Windows NT 6.0') { $this->uadata['os'] = 'Windows Vista'; }
1352 elseif ($this->uadata['os'] == 'Windows NT 6.0 (Win64)') { $this->uadata['os'] = 'Windows Vista (64bit)'; }
1353 elseif ($this->uadata['os'] == 'Windows NT 6.0 (WOW64)') { $this->uadata['os'] = 'Windows Vista (64bit)'; }
1354 elseif ($this->uadata['os'] == 'Windows NT 6.1') { $this->uadata['os'] = 'Windows 7'; }
1355 elseif ($this->uadata['os'] == 'Windows NT 6.1 (Win64)') { $this->uadata['os'] = 'Windows 7 (64bit)'; }
1356 elseif ($this->uadata['os'] == 'Windows NT 6.1 (WOW64)') { $this->uadata['os'] = 'Windows 7 (64bit)'; }
1357 elseif ($this->uadata['os'] == 'Win95') { $this->uadata['os'] = 'Windows 95'; }
1358 elseif ($this->uadata['os'] == 'Win98') { $this->uadata['os'] = 'Windows 98'; }
1359 elseif ($this->uadata['os'] == 'WinNT') { $this->uadata['os'] = 'Windows NT'; }
1360 elseif ($this->uadata['os'] == 'Win32') { $this->uadata['os'] = 'Windows (32bit)'; }
1361 elseif ($this->uadata['os'] == 'Win64') { $this->uadata['os'] = 'Windows (64bit)'; }
1362 elseif (preg_match('/iPhone OS ([\d_]+)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'iOS '.str_replace('_', '.', $regs[1]); }
1363 elseif (preg_match('/Mac ?OS ?X/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; }
1364 elseif (preg_match('/Mac_P(ower|)PC/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; }
1365 elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
1366 elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
1367 elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
1368 elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
1369 elseif (preg_match('/Android \(Linux (.+)\)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'Android '.$regs[1]; }
1370 elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
1371 elseif (preg_match('/SymbianOS[\/ ]([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) { $this->uadata['os'] = 'SymbianOS '.$regs[1]; }
1372 elseif (preg_match('/Symbian ?OS/i', $this->uadata['os'])) { $this->uadata['os'] = 'SymbianOS'; }
1374 if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
1375 elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
1376 elseif (strpos($this->uadata['os'], 'iOS') !== false) { $this->uadata['platform'] = 'Macintosh'; }
1377 elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
1378 elseif (strpos($this->uadata['os'], 'MeeGo') !== false) { $this->uadata['platform'] = 'Linux'; }
1379 elseif (strpos($this->uadata['os'], 'Android') !== false) { $this->uadata['platform'] = 'Android'; }
1380 elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
1381 elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
1382 elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
1383 elseif (strpos($this->uadata['os'], 'BePC') !== false) { $this->uadata['platform'] = 'BeOS'; }
1384 elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
1385 elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
1386 elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
1387 elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
1388 elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
1389 elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
1390 elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
1391 elseif (strpos($this->uadata['os'], 'webOS') !== false) { $this->uadata['platform'] = 'webOS'; }
1392 elseif (strpos($this->uadata['os'], 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; }
1393 elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
1394 elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
1395 elseif (strpos($this->uadata['os'], 'OS/2') !== false) { $this->uadata['platform'] = 'OS/2'; }
1396 elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
1397 elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->uadata['platform'] = 'Nintendo'; }
1398 elseif (strpos($this->uadata['os'], 'Wii') !== false) { $this->uadata['platform'] = 'Nintendo'; }
1399 elseif (strpos($this->uadata['os'], 'Nintendo') !== false) { $this->uadata['platform'] = 'Nintendo'; }
1400 elseif (strpos($this->uadata['os'], 'J2ME') !== false) { $this->uadata['platform'] = 'Java'; }
1401 elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
1402 elseif (strpos($this->uadata['os'], 'mingw') !== false) { $this->uadata['platform'] = 'Windows'; }
1403 else { $this->uadata['platform'] = $this->uadata['os']; }
1405 $this->uadata['lang'] = str_replace('_', '-', $this->uadata['lang']);
1408 return $this->uadata['os'];
1411 public function getPlatform() {
1412 if (!isset($this->uadata['platform'])) {
1413 $this->uadata['platform'] = null;
1414 // getOS() should get the date for us
1417 return $this->uadata['platform'];
1420 public function getLanguage() {
1421 if (!isset($this->uadata['lang'])) {
1422 $this->uadata['lang'] = null;
1423 // getOS() should get the date for us
1426 return $this->uadata['lang'];
1429 public function getGeckoDate() {
1430 if (!isset($this->uadata['geckodate'])) {
1431 $this->uadata['geckodate'] = null;
1432 // getEngine() should get the date for us
1435 return $this->uadata['geckodate'];
1438 public function getGeckoTime() {
1439 if (!isset($this->uadata['geckotime'])) {
1440 $this->uadata['geckotime'] = null;
1441 if (!is_null($this->getGeckoDate())) {
1442 $use_time = (strlen($this->getGeckoDate()) > 8);
1443 $gd_str = substr($this->getGeckoDate(),0,4).'-'.substr($this->getGeckoDate(),4,2).'-'.substr($this->getGeckoDate(),6,2);
1445 $gd_str .= substr($this->getGeckoDate(),8,2).':00';
1446 $old_tz = date_default_timezone_get();
1447 date_default_timezone_set("America/Los_Angeles");
1449 $this->uadata['geckotime'] = strtotime($gd_str);
1450 if ($use_time) { date_default_timezone_set($old_tz); }
1453 return $this->uadata['geckotime'];
1456 public function isBot() { return $this->bot; }
1458 public function isns() {
1459 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1460 return (strpos($this->brand, 'Netscape') !== false);
1462 public function isns4() {
1463 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1464 return ((strpos($this->brand, 'Netscape') !== false) && (intval($this->version) == 4));
1466 public function isie() {
1467 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1468 return $this->hasEngine('trident');
1470 public function geckodate() {
1471 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1472 return (!is_null($this->getGeckoDate())?$this->getGeckoDate():0);
1474 public function geckobased() {
1475 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1476 return $this->hasEngine('gecko');
1478 public function khtmlbased() {
1479 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1480 return $this->hasEngine('khtml');