add methods for password fields
[php-utility-classes.git] / include / classes / useragent.php-class
... / ...
CommitLineData
1<?php
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
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/
9 *
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
13 * License.
14 *
15 * The Original Code is KaiRo's userAgent detection.
16 *
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.
21 *
22 * Contributor(s): Robert Kaiser <kairo@kairo.at>
23 *
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.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38class userAgent {
39 // userAgent PHP class
40 // get user agent and tell us what Browser is accessing
41 //
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.
44 //
45 // private $uastring
46 // the plain User Agent string
47 // private $brand
48 // the User Agent brand name
49 // private $version
50 // the User Agent version
51 // private $bot
52 // bool: true if this agent is a bot
53 // private $mobile
54 // bool: true if this agent is a mobile phone
55 // private $uadata
56 // array of static user agent data (static vars in functions are set for all objects of this class!)
57 //
58 // public function getBrand()
59 // returns the User Agent Brand Name
60 //
61 // public function getVersion()
62 // returns the User Agent version
63 //
64 // public function getAcceptLanguages()
65 // returns an associated array with the accepted languages of this UA
66 // keys are language codes, values are q factors (weights)
67 //
68 // public function getUAString()
69 // returns the full User Agent string
70 //
71 // public function getEngine()
72 // returns a string telling the detected rendering engine, null if we can't detect
73 // one of gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|unknown
74 //
75 // public function hasEngine($rnd_engine)
76 // returns true if the given rendering engine was detected
77 //
78 // public function getEngineVersion()
79 // returns a the version number for the rendering engine
80 // this may be the same as getVersion() for many engines, or null if we don't know
81 //
82 // public function getOS()
83 // returns a string telling the detected operating system, null if we can't detect
84 // might be very verbose, uses no abbreviations for most names
85 //
86 // public function getPlatform()
87 // returns a string telling the detected OS platform, null if we can't detect
88 // one of windows|linux|mac|solaris|unknown
89 //
90 // public function getLanguage() {
91 // returns a string telling the detected browser UI language, null if we can't detect
92 // should be an ISO code
93 //
94 // public function isBot()
95 // returns true if User Agent seems to be a bot
96 //
97 // public function isMobile()
98 // returns true if User Agent seems to be a mobile phone
99 //
100 // *** functions that only return useable info for some agents ***
101 //
102 // public function getGeckoDate()
103 // returns the Gecko date for Gecko-based browsers, null for others
104 //
105 // public function getGeckoTime()
106 // returns the Gecko build date/time as a unix epoch time number for Gecko-based browsers, null for others
107 //
108 // *** functions for compat to older versions of this class ***
109 //
110 // public function isns()
111 // returns true if User Agent seems to be Netscape brand, false if not
112 // public function isns4()
113 // returns true if User Agent seems to be Netscape Communicator 4.x, false if not
114 // public function isie()
115 // returns true if User Agent seems to be a version of Internet Exploder, false if not
116 // public function geckobased()
117 // returns true if User Agent seems to be a Gecko-based browser, false if not
118 // public function geckodate()
119 // returns the Gecko date when it's a Gecko-based browser, 0 if not
120 // public function khtmlbased()
121 // returns true if User Agent seems to be a KHTML-based browser, false if not
122
123 // collection of some known User Agent Strings:
124 // *** see testbed/ua_list_raw.txt ***
125 // *** see also http://www.pgts.com.au/pgtsj/pgtsj0208c.html ***
126
127 private $uastring;
128 private $brand;
129 private $version;
130 private $bot = false;
131 private $mobile = false;
132 private $uadata = array();
133
134 function __construct($ua_string = '') {
135 // *** constructor ***
136 if (strlen($ua_string)) {
137 $this->uastring = $ua_string;
138 }
139 else {
140 // read raw UA string
141 $this->uastring = $_SERVER['HTTP_USER_AGENT'];
142 }
143
144 // get UA brand and version
145 $this->brand = 'Unknown'; $this->version = null;
146 // find reasonable defaults
147 if (preg_match('|([0-9a-zA-Z\.:()_ -]+)/(\d[0-9a-zA-Z\._+-]*)|', $this->uastring, $regs)) {
148 $this->brand = trim($regs[1]);
149 $this->version = $regs[2];
150 }
151 elseif (preg_match('|^([a-zA-Z\._ -]+)[_ -][vV]?(\d[0-9a-zA-Z\.+]*)|', $this->uastring, $regs)) {
152 $this->brand = trim($regs[1]);
153 $this->version = $regs[2];
154 }
155 elseif (preg_match('|^([0-9a-zA-Z\._ -]+)|', $this->uastring, $regs)) {
156 $this->brand = trim($regs[1]);
157 $this->version = null;
158 }
159 $this->bot = (strpos(strtolower($this->brand), 'bot') !== false)
160 || (strpos(strtolower($this->brand), 'crawler') !== false)
161 || (strpos(strtolower($this->brand), 'spider') !== false)
162 || (strpos(strtolower($this->brand), 'search') !== false)
163 || (strpos(strtolower($this->brand), 'seek') !== false);
164
165 // search for any real and/or special UAs
166 if (preg_match('|Netscape6/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
167 $this->brand = 'Netscape';
168 $this->version = $regs[1];
169 $this->bot = false;
170 }
171 elseif (preg_match('|Netscape/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
172 $this->brand = 'Netscape';
173 $this->version = $regs[1];
174 $this->bot = false;
175 }
176 elseif (preg_match('|Navigator/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
177 $this->brand = 'Netscape';
178 $this->version = $regs[1];
179 $this->bot = false;
180 }
181 elseif (preg_match('|Chimera/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
182 $this->brand = 'Chimera';
183 $this->version = $regs[1];
184 $this->bot = false;
185 }
186 elseif (preg_match('|Camino/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
187 $this->brand = 'Camino';
188 $this->version = $regs[1];
189 $this->bot = false;
190 }
191 elseif (preg_match('|Phoenix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
192 $this->brand = 'Phoenix';
193 $this->version = $regs[1];
194 $this->bot = false;
195 }
196 elseif (preg_match('|Mozilla Firebird/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
197 $this->brand = 'Mozilla Firebird';
198 $this->version = $regs[1];
199 $this->bot = false;
200 }
201 elseif (preg_match('|Flock/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
202 $this->brand = 'Flock';
203 $this->version = $regs[1];
204 $this->bot = false;
205 }
206 elseif (preg_match('|SeaMonkey/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
207 $this->brand = 'SeaMonkey';
208 $this->version = $regs[1];
209 $this->bot = false;
210 }
211 elseif (preg_match('|Iceape/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
212 $this->brand = 'IceApe'; // Debian-rebranded SeaMonkey
213 $this->version = $regs[1];
214 $this->bot = false;
215 }
216 elseif (preg_match('|Iceweasel/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
217 $this->brand = 'IceWeasel'; // Debian-rebranded Firefox
218 $this->version = $regs[1];
219 $this->bot = false;
220 }
221 elseif (preg_match('|Icedove/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
222 $this->brand = 'IceDove'; // Debian-rebranded Thunderbird
223 $this->version = $regs[1];
224 $this->bot = false;
225 }
226 elseif (preg_match('|BonEcho/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
227 $this->brand = 'Bon Echo'; // Firefox 2.0 code name
228 $this->version = $regs[1];
229 $this->bot = false;
230 }
231 elseif (preg_match('|GranParadiso/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
232 $this->brand = 'Gran Paradiso'; // Firefox 3.0 code name
233 $this->version = $regs[1];
234 $this->bot = false;
235 }
236 elseif (preg_match('|Shiretoko/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
237 $this->brand = 'Shiretoko'; // Firefox 3.5 code name
238 $this->version = $regs[1];
239 $this->bot = false;
240 }
241 elseif (preg_match('|Namoroka/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
242 $this->brand = 'Namoroka'; // Firefox 3.6 code name
243 $this->version = $regs[1];
244 $this->bot = false;
245 }
246 elseif (preg_match('|Lorentz/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
247 $this->brand = 'Lorentz'; // Firefox 3.6 (with OOPP) code name
248 $this->version = $regs[1];
249 $this->bot = false;
250 }
251 elseif (preg_match('|Minefield/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
252 $this->brand = 'Minefield'; // Firefox development nightly code name
253 $this->version = $regs[1];
254 $this->bot = false;
255 }
256 elseif (preg_match('|PmWFx/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
257 $this->brand = 'PmW-Firefox';
258 $this->version = $regs[1];
259 $this->bot = false;
260 }
261 elseif (preg_match('|BeZillaBrowser/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
262 $this->brand = 'BeZillaBrowser';
263 $this->version = $regs[1];
264 $this->bot = false;
265 }
266 elseif (preg_match('|Songbird/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
267 $this->brand = 'Songbird';
268 $this->version = $regs[1];
269 $this->bot = false;
270 }
271 elseif (preg_match('|Lanikai/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
272 $this->brand = 'Lanikai'; // Thunderbird 3.1 code name
273 $this->version = $regs[1];
274 $this->bot = false;
275 }
276 elseif (preg_match('|Shredder/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
277 $this->brand = 'Shredder'; // Thunderbird development nightly code name
278 $this->version = $regs[1];
279 $this->bot = false;
280 }
281 elseif (preg_match('|prism/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
282 $this->brand = 'Prism';
283 $this->version = $regs[1];
284 $this->bot = false;
285 }
286 elseif (preg_match('|Minimo/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
287 $this->brand = 'Minimo';
288 $this->version = $regs[1];
289 $this->bot = false;
290 $this->mobile = true;
291 }
292 elseif (preg_match('|Fennec/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
293 $this->brand = 'Fennec'; // Firefox mobile code name
294 $this->version = $regs[1];
295 $this->bot = false;
296 $this->mobile = true;
297 }
298 elseif (preg_match('|Galeon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
299 $this->brand = 'Galeon';
300 $this->version = $regs[1];
301 $this->bot = false;
302 }
303 elseif (preg_match('|Epiphany/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
304 $this->brand = 'Epiphany';
305 $this->version = $regs[1];
306 $this->bot = false;
307 }
308 elseif (preg_match('|K-Meleon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
309 $this->brand = 'K-Meleon';
310 $this->version = $regs[1];
311 $this->bot = false;
312 }
313 elseif (preg_match('|AOL[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
314 $this->brand = 'AOL';
315 $this->version = $regs[1];
316 $this->bot = false;
317 }
318 elseif (preg_match('|Tablet browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
319 $this->brand = 'microB';
320 $this->version = $regs[1];
321 $this->bot = false;
322 $this->mobile = true;
323 }
324 elseif (preg_match('|Maemo Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
325 $this->brand = 'microB';
326 $this->version = $regs[1];
327 $this->bot = false;
328 $this->mobile = true;
329 }
330 elseif (preg_match('|Opera\/([^\(]+) \(.*; Opera Mini; |', $this->uastring, $regs)) {
331 $this->brand = 'Opera Mini';
332 $this->version = $regs[1];
333 $this->bot = false;
334 $this->mobile = true;
335 }
336 elseif (preg_match('/Opera\/[^\(]+ \(.*; Opera Mini\/([^;]+); /i', $this->uastring, $regs)) {
337 $this->brand = 'Opera Mini';
338 $this->version = $regs[1];
339 $this->bot = false;
340 $this->mobile = true;
341 }
342 elseif (preg_match('|Opera[ /]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
343 $this->brand = 'Opera';
344 $this->version = $regs[1];
345 $this->bot = false;
346 }
347 elseif (preg_match('|OmniWeb/([0-9a-zA-Z\.+-]+)|', $this->uastring, $regs)) {
348 $this->brand = 'OmniWeb';
349 $this->version = $regs[1];
350 $this->bot = false;
351 }
352 elseif (preg_match('|Konqueror/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
353 $this->brand = 'Konqueror';
354 $this->version = $regs[1];
355 $this->bot = false;
356 }
357 elseif (preg_match('|Shiira/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
358 $this->brand = 'Shiira';
359 $this->version = $regs[1];
360 $this->bot = false;
361 }
362 elseif (preg_match('|Edge/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
363 $this->brand = 'Edge';
364 $this->version = $regs[1];
365 $this->bot = false;
366 }
367 elseif (preg_match('|Chromium/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
368 $this->brand = 'Chromium';
369 $this->version = $regs[1];
370 $this->bot = false;
371 }
372 elseif (preg_match('|Chrome/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
373 $this->brand = 'Chrome';
374 $this->version = $regs[1];
375 $this->bot = false;
376 }
377 elseif (preg_match('|NokiaBrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
378 $this->brand = 'NokiaBrowser';
379 $this->version = $regs[1];
380 $this->bot = false;
381 }
382 elseif (preg_match('|wOSBrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
383 $this->brand = 'webOS Browser';
384 $this->version = $regs[1];
385 $this->bot = false;
386 }
387 elseif (preg_match('|Silk/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
388 $this->brand = 'Silk';
389 $this->version = $regs[1];
390 $this->bot = false;
391 }
392 elseif (preg_match('|Kindle/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
393 $this->brand = 'Kindle';
394 $this->version = $regs[1];
395 $this->bot = false;
396 }
397 elseif (preg_match('|Pre/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
398 $this->brand = 'Pre';
399 $this->version = $regs[1];
400 $this->bot = false;
401 }
402 elseif (preg_match('|BOLT/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
403 $this->brand = 'BOLT';
404 $this->version = $regs[1];
405 $this->bot = false;
406 }
407 elseif (preg_match('|Googlebot-Mobile/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Webkit! */
408 $this->brand = 'Googlebot-Mobile';
409 $this->version = $regs[1];
410 $this->bot = true;
411 $this->mobile = true;
412 }
413 elseif (preg_match('|Safari/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
414 if (preg_match('| Mobile(/[0-9a-zA-Z\.+]+)? ?Safari/|', $this->uastring)) {
415 $this->brand = 'Mobile Safari';
416 $this->mobile = true;
417 }
418 else {
419 $this->brand = 'Safari';
420 }
421 if (preg_match('|Version/([0-9a-zA-Z\.+]+)|', $this->uastring, $vregs)) {
422 $this->version = $vregs[1];
423 }
424 else {
425 $this->version = '('.$regs[1].')';
426 }
427 $this->bot = false;
428 }
429 elseif (preg_match('|AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
430 $this->brand = 'AppleWebKit';
431 $this->version = $regs[1];
432 $this->bot = false;
433 }
434 elseif (preg_match('|Spinn3r ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
435 $this->brand = 'Spinn3r';
436 $this->version = $regs[1];
437 $this->bot = true;
438 }
439 elseif (preg_match('|Butterfly/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
440 $this->brand = 'Butterfly';
441 $this->version = $regs[1];
442 $this->bot = true;
443 }
444 elseif (preg_match('|Googlebot/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
445 $this->brand = 'Googlebot';
446 $this->version = $regs[1];
447 $this->bot = true;
448 }
449 elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
450 $this->brand = 'Firefox';
451 $this->version = $regs[1];
452 $this->bot = false;
453 }
454 elseif (preg_match('|Thunderbird/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
455 $this->brand = 'Thunderbird';
456 $this->version = $regs[1];
457 $this->bot = false;
458 }
459 elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
460 strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
461 $this->brand = 'Mozilla';
462 $this->version = $regs[1];
463 $this->bot = false;
464 }
465 elseif (preg_match('|m([0-9]+)\)|', $this->uastring, $regs) &&
466 strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
467 $this->brand = 'Mozilla';
468 $this->version = 'M'.$regs[1];
469 $this->bot = false;
470 }
471 elseif (preg_match('|Baiduspider|i', $this->uastring)) {
472 $this->brand = 'BaiDuSpider';
473 $this->version = null;
474 $this->bot = true;
475 }
476 elseif (preg_match('|YodaoBot-Mobile/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
477 $this->brand = 'YodaoBot-Mobile';
478 $this->version = $regs[1];
479 $this->bot = true;
480 $this->mobile = true;
481 }
482 elseif (preg_match('|FASTMobileCrawl/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
483 $this->brand = 'FASTMobileCrawl';
484 $this->version = $regs[1];
485 $this->bot = true;
486 $this->mobile = true;
487 }
488 elseif (preg_match('|MSFrontPage/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
489 $this->brand = 'Microsoft FrontPage';
490 $this->version = $regs[1];
491 $this->bot = false;
492 }
493 elseif (preg_match('|iCab[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
494 $this->brand = 'iCab';
495 $this->version = $regs[1];
496 $this->bot = false;
497 }
498 elseif (preg_match('|IBrowse[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
499 $this->brand = 'IBrowse';
500 $this->version = $regs[1];
501 $this->bot = false;
502 }
503 elseif (preg_match('|ICEbrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
504 $this->brand = 'ICEbrowser';
505 $this->version = $regs[1];
506 $this->bot = false;
507 }
508 elseif (preg_match('|ICE Browser/v([0-9a-zA-Z\._+]+)|', $this->uastring, $regs)) {
509 $this->brand = 'ICEbrowser';
510 $this->version = str_replace('_', '.', $regs[1]);
511 $this->bot = false;
512 }
513 elseif (preg_match('|NetPositive/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
514 $this->brand = 'NetPositive';
515 $this->version = $regs[1];
516 $this->bot = false;
517 }
518 elseif (preg_match('|WebPro/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
519 $this->brand = 'WebPro (Novarra)';
520 $this->version = $regs[1];
521 $this->bot = false;
522 }
523 elseif (preg_match('|; OffByOne;|', $this->uastring, $regs)) {
524 $this->brand = 'Off By One';
525 $this->version = null;
526 $this->bot = false;
527 }
528 elseif (preg_match('|PSP \(PlayStation Portable\); ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
529 $this->brand = 'PlayStation Portable';
530 $this->version = $regs[1];
531 $this->bot = false;
532 $this->mobile = true;
533 }
534 elseif (preg_match('|PLAYSTATION 3; ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
535 $this->brand = 'PlayStation 3';
536 $this->version = $regs[1];
537 $this->bot = false;
538 }
539 elseif (preg_match('|NetFront/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
540 $this->brand = 'NetFront';
541 $this->version = $regs[1];
542 $this->bot = false;
543 $this->mobile = true;
544 }
545 elseif (preg_match('|UP.Browser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
546 $this->brand = 'UP.Browser';
547 $this->version = $regs[1];
548 $this->bot = false;
549 $this->mobile = true;
550 }
551 elseif (preg_match('|UP.Link/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
552 $this->brand = 'UP.Link';
553 $this->version = $regs[1];
554 $this->bot = false;
555 $this->mobile = true;
556 }
557 elseif (preg_match('|AU-MIC-([0-9A-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
558 $this->brand = 'Obigo';
559 $this->version = $regs[1];
560 $this->bot = false;
561 $this->mobile = true;
562 }
563 elseif (preg_match('|Browser/Obigo-([0-9A-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
564 $this->brand = 'Obigo';
565 $this->version = $regs[1];
566 $this->bot = false;
567 $this->mobile = true;
568 }
569 elseif (preg_match('|Nokia([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
570 $this->brand = 'Nokia';
571 $this->version = $regs[1];
572 $this->bot = false;
573 $this->mobile = true;
574 }
575 elseif (preg_match('|SonyEricsson([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
576 $this->brand = 'SonyEricsson';
577 $this->version = $regs[1];
578 $this->bot = false;
579 $this->mobile = true;
580 }
581 elseif (preg_match('|SIE-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
582 $this->brand = 'Siemens';
583 $this->version = $regs[1];
584 $this->bot = false;
585 $this->mobile = true;
586 }
587 elseif (preg_match('|MOT-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
588 $this->brand = 'Motorola';
589 $this->version = $regs[1];
590 $this->bot = false;
591 $this->mobile = true;
592 }
593 elseif (preg_match('|IXI/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
594 $this->brand = 'IXI';
595 $this->version = $regs[1];
596 $this->bot = false;
597 $this->mobile = true;
598 }
599 elseif (preg_match('|NewsFox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
600 $this->brand = 'NewsFox';
601 $this->version = $regs[1];
602 $this->bot = false;
603 }
604 elseif (preg_match('|rdfbot/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
605 $this->brand = 'rdfbot';
606 $this->version = $regs[1];
607 $this->bot = false;
608 }
609 elseif (preg_match('|IBM-WebExplorer-DLL/v([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
610 $this->brand = 'WebExplorer';
611 $this->version = $regs[1];
612 $this->bot = false;
613 }
614 elseif (preg_match('|ELinks \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
615 $this->brand = 'ELinks';
616 $this->version = $regs[1];
617 $this->bot = false;
618 }
619 elseif (preg_match('|Links \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
620 $this->brand = 'Links';
621 $this->version = $regs[1];
622 $this->bot = false;
623 }
624 elseif (preg_match('|WinHttp.WinHttpRequest.([0-9\.]+)|i', $this->uastring, $regs)) {
625 $this->brand = 'WinHttpRequest';
626 $this->version = $regs[1];
627 $this->bot = false;
628 }
629 elseif (preg_match('|alpha[/ ]06; AmigaOS|i', $this->uastring, $regs)) {
630 $this->brand = 'Alpha 06';
631 $this->version = null;
632 $this->bot = false;
633 }
634 elseif (preg_match('|; arexx[\);]|i', $this->uastring, $regs)) {
635 $this->brand = 'ARexx';
636 $this->version = null;
637 $this->bot = false;
638 }
639 elseif (preg_match('|; Voyager; AmigaOS[\);]|i', $this->uastring, $regs)) {
640 $this->brand = 'AmigaVoyager';
641 $this->version = null;
642 $this->bot = false;
643 }
644 elseif (preg_match('|AWEB ([0-9a-zA-Z\.+ ]+)|', $this->uastring, $regs)) {
645 $this->brand = 'AWEB';
646 $this->version = $regs[1];
647 $this->bot = false;
648 }
649 elseif (preg_match('|X ([0-9a-zA-Z\.+ ]+); Commodore 64|', $this->uastring, $regs)) {
650 $this->brand = 'X';
651 $this->version = $regs[1];
652 $this->bot = false;
653 }
654 elseif (preg_match('|DB Browse ([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
655 $this->brand = 'DB Browse';
656 $this->version = $regs[1];
657 $this->bot = false;
658 }
659 elseif (preg_match('|ZyBorg/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
660 $this->brand = 'ZyBorg';
661 $this->version = $regs[1];
662 $this->bot = true;
663 }
664 elseif (preg_match('|Ask Jeeves/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
665 $this->brand = 'Ask Jeeves';
666 $this->version = $regs[1];
667 $this->bot = true;
668 }
669 elseif (preg_match('|heritrix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
670 $this->brand = 'Heritrix';
671 $this->version = $regs[1];
672 $this->bot = true;
673 }
674 elseif (preg_match('|heritrix([0-9a-zA-Z\.+-]+)|', $this->uastring, $regs)) {
675 $this->brand = 'Heritrix';
676 $this->version = str_replace('-', '.', $regs[1]);
677 $this->bot = true;
678 }
679 elseif (preg_match('|SBSearch/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
680 $this->brand = 'SBSearch';
681 $this->version = $regs[1];
682 $this->bot = true;
683 }
684 elseif (preg_match('|Powermarks/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
685 $this->brand = 'Powermarks';
686 $this->version = $regs[1];
687 $this->bot = true;
688 }
689 elseif (preg_match('|TopBlogsInfo/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
690 $this->brand = 'TopBlogsInfo';
691 $this->version = $regs[1];
692 $this->bot = true;
693 }
694 elseif (preg_match('|picmole/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
695 $this->brand = 'picmole';
696 $this->version = $regs[1];
697 $this->bot = true;
698 }
699 elseif (preg_match('|([0-9a-zA-Z\._+-]+bot)/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
700 $this->brand = $regs[1];
701 $this->version = $regs[2];
702 $this->bot = true;
703 }
704 elseif (preg_match('|VoilaBot ((BETA )?[0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
705 $this->brand = 'VoilaBot';
706 $this->version = $regs[1];
707 $this->bot = true;
708 }
709 elseif (preg_match('|Slurp|', $this->uastring, $regs)) {
710 $this->brand = 'Slurp';
711 $this->version = null;
712 $this->bot = true;
713 }
714 elseif (preg_match('|Check&amp;Get ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
715 $this->brand = 'Check&Get';
716 $this->version = $regs[1];
717 $this->bot = true;
718 }
719 elseif (preg_match('|WebCapture ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
720 $this->brand = 'WebCapture';
721 $this->version = $regs[1];
722 $this->bot = true;
723 }
724 elseif (preg_match('|WebMon ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
725 $this->brand = 'WebMon';
726 $this->version = $regs[1];
727 $this->bot = true;
728 }
729 elseif (preg_match('|Gulper Web Bot ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
730 $this->brand = 'Gulper Web Bot';
731 $this->version = $regs[1];
732 $this->bot = true;
733 }
734 elseif (preg_match('|HTTrack ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
735 $this->brand = 'HTTrack';
736 $this->version = $regs[1];
737 $this->bot = true;
738 }
739 elseif (preg_match('|Advista Crawler ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
740 $this->brand = 'HTTrack';
741 $this->version = $regs[1];
742 $this->bot = true;
743 }
744 elseif (preg_match('|Seznam screenshot-generator ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
745 $this->brand = 'Seznam screenshot-generator';
746 $this->version = $regs[1];
747 $this->bot = true;
748 }
749 elseif (preg_match('|Yahoo! SearchMonkey ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
750 $this->brand = 'Yahoo! SearchMonkey';
751 $this->version = $regs[1];
752 $this->bot = true;
753 }
754 elseif (preg_match('|Yahoo Pipes ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
755 $this->brand = 'Yahoo! Pipes';
756 $this->version = $regs[1];
757 $this->bot = true;
758 }
759 elseif (preg_match('|Firebat ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
760 $this->brand = 'Firebat';
761 $this->version = $regs[1];
762 $this->bot = true;
763 }
764 elseif (preg_match('|Twiceler-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
765 $this->brand = 'Twiceler';
766 $this->version = $regs[1];
767 $this->bot = true;
768 }
769 elseif (preg_match('|Nu_?tch-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
770 $this->brand = 'Nutch';
771 $this->version = $regs[1];
772 $this->bot = true;
773 }
774 elseif (preg_match('|Microsoft URL Control - ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
775 $this->brand = 'Microsoft URL Control';
776 $this->version = $regs[1];
777 $this->bot = true;
778 }
779 elseif (preg_match('|([0-9a-zA-Z\.+]+)_AC-Plug|', $this->uastring, $regs)) {
780 $this->brand = 'AC-Plug';
781 $this->version = $regs[1];
782 $this->bot = true;
783 }
784 elseif (preg_match('|^Internet Explorer 5.5|', $this->uastring)) {
785 $this->brand = 'Unknown bot (IE5.5)';
786 $this->version = null;
787 $this->bot = true;
788 }
789 elseif (preg_match('|^Mozilla[\s ]*$|', $this->uastring)) {
790 $this->brand = 'Unknown bot (Mozilla)';
791 $this->version = null;
792 $this->bot = true;
793 }
794 elseif (preg_match('|ICCrawler|i', $this->uastring, $regs)) {
795 $this->brand = 'ICCrawler';
796 $this->version = null;
797 $this->bot = true;
798 }
799 elseif (preg_match('|KaloogaBot|', $this->uastring, $regs)) {
800 $this->brand = 'KaloogaBot';
801 $this->version = null;
802 $this->bot = true;
803 }
804 elseif (preg_match('|ScoutJet|', $this->uastring, $regs)) {
805 $this->brand = 'ScoutJet';
806 $this->version = null;
807 $this->bot = true;
808 }
809 elseif (preg_match('|http://www.livedir.net|', $this->uastring, $regs)) {
810 $this->brand = 'livedir.net';
811 $this->version = null;
812 $this->bot = true;
813 }
814 elseif (preg_match('|WebClipping.com|', $this->uastring, $regs)) {
815 $this->brand = 'WebClipping.com';
816 $this->version = null;
817 $this->bot = true;
818 }
819 elseif (preg_match('|newstin.com|', $this->uastring, $regs)) {
820 $this->brand = 'newstin.com';
821 $this->version = null;
822 $this->bot = true;
823 }
824 elseif (preg_match('|http://www.almaden.ibm.com/cs/crawler|', $this->uastring)) {
825 $this->brand = 'almaden crawler';
826 $this->version = null;
827 $this->bot = true;
828 }
829 elseif (preg_match('|B-l-i-t-z-B-O-T|', $this->uastring) ||
830 preg_match('|B l i t z B O T @ t r i c u s . n e t|', $this->uastring)) {
831 $this->brand = 'BlitzBOT';
832 $this->version = null;
833 $this->bot = true;
834 }
835 elseif (preg_match('|Really Gmane.org\'s favicon grabber|', $this->uastring)) {
836 $this->brand = 'Really Gmane.org\'s favicon grabber';
837 $this->version = null;
838 $this->bot = true;
839 }
840 elseif (preg_match('|Girafabot|', $this->uastring)) {
841 $this->brand = 'Girafabot';
842 $this->version = null;
843 $this->bot = true;
844 }
845 elseif (preg_match('|Arachmo|', $this->uastring)) {
846 $this->brand = 'Arachmo';
847 $this->version = null;
848 $this->bot = true;
849 }
850 elseif (preg_match('|OsO|', $this->uastring)) {
851 $this->brand = 'OsO';
852 $this->version = null;
853 $this->bot = true;
854 }
855 elseif (preg_match('|Yoono|', $this->uastring)) {
856 $this->brand = 'Yoono';
857 $this->version = null;
858 $this->bot = true;
859 }
860 elseif (preg_match('|efp@gmx.net|', $this->uastring)) {
861 $this->brand = 'efp';
862 $this->version = null;
863 $this->bot = true;
864 }
865 elseif (preg_match('|Indy Library|', $this->uastring)) {
866 $this->brand = 'Indy Library';
867 $this->version = null;
868 $this->bot = true;
869 }
870 elseif (preg_match('|Linkman|', $this->uastring)) {
871 $this->brand = 'Linkman';
872 $this->version = null;
873 $this->bot = true;
874 }
875 elseif (preg_match('|Sage|', $this->uastring, $regs)) {
876 $this->brand = 'Sage';
877 $this->version = null;
878 $this->bot = true;
879 }
880 elseif (preg_match('|Google Desktop|', $this->uastring)) {
881 $this->brand = 'Google Desktop';
882 $this->version = null;
883 $this->bot = true;
884 }
885 elseif (preg_match('|^Firefly|', $this->uastring)) {
886 // comes here with correct value but would be detected as MSIE
887 }
888 elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
889 $this->brand = 'Steganos Internet Anonym';
890 $this->version = $regs[1];
891 $this->bot = false;
892 }
893 elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
894 $this->brand = 'Steganos Internet Anonym';
895 $this->version = $regs[1];
896 $this->bot = false;
897 }
898 elseif (preg_match('|BorderManager ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
899 $this->brand = 'BorderManager';
900 $this->version = $regs[1];
901 $this->bot = false;
902 }
903 elseif (preg_match('|WebWasher ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
904 $this->brand = 'WebWasher';
905 $this->version = $regs[1];
906 $this->bot = false;
907 }
908 elseif (preg_match('|SaferSurf|', $this->uastring, $regs)) {
909 $this->brand = 'SaferSurf';
910 $this->version = null;
911 $this->bot = false;
912 }
913 elseif (preg_match('|Avant Browser[^/]|', $this->uastring)) {
914 $this->brand = 'Avant Browser';
915 $this->version = null;
916 $this->bot = false;
917 }
918 elseif (preg_match('|Browser[^/]+(http://www.avantbrowser.com)|', $this->uastring)) {
919 $this->brand = 'Avant Browser';
920 $this->version = null;
921 $this->bot = false;
922 }
923 elseif (preg_match('|Maxthon|', $this->uastring)) {
924 $this->brand = 'Maxthon';
925 $this->version = null;
926 $this->bot = false;
927 }
928 elseif (preg_match('|MyIE2|', $this->uastring)) {
929 $this->brand = 'MyIE2';
930 $this->version = null;
931 $this->bot = false;
932 }
933 elseif (preg_match('|Crazy Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
934 $this->brand = 'Crazy Browser';
935 $this->version = $regs[1];
936 $this->bot = false;
937 }
938 elseif (preg_match('|AvantGo ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
939 $this->brand = 'AvantGo';
940 $this->version = $regs[1];
941 $this->bot = false;
942 }
943 elseif (preg_match('|MSN ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
944 $this->brand = 'MSN';
945 $this->version = $regs[1];
946 $this->bot = false;
947 }
948 elseif (preg_match('|America Online Browser [0-9a-zA-Z\.+]+; rev([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
949 $this->brand = 'AOL Browser';
950 $this->version = $regs[1];
951 $this->bot = false;
952 }
953 elseif (preg_match('|MS FrontPage ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
954 $this->brand = 'Microsoft FrontPage';
955 $this->version = $regs[1];
956 $this->bot = false;
957 }
958 elseif (preg_match('|Microsoft Internet Explorer/4.0b1|', $this->uastring, $regs)) {
959 $this->brand = 'Microsoft Internet Explorer';
960 $this->version = '1.0';
961 $this->bot = false;
962 }
963 elseif (preg_match('|MSIE 7\.0.+Trident/4.0|', $this->uastring, $regs)) {
964 $this->brand = 'Microsoft Internet Explorer';
965 $this->version = "8.0";
966 $this->bot = false;
967 }
968 elseif (preg_match('|MSIE 7\.0.+Trident/5.0|', $this->uastring, $regs)) {
969 $this->brand = 'Microsoft Internet Explorer';
970 $this->version = "9.0";
971 $this->bot = false;
972 }
973 elseif (preg_match('|MSIE 7\.0.+Trident/6.0|', $this->uastring, $regs)) {
974 $this->brand = 'Microsoft Internet Explorer';
975 $this->version = "10.0";
976 $this->bot = false;
977 }
978 elseif (preg_match('|Trident\/[0-9a-zA-Z\.+]+; ([^\)]+; )?rv:([0-9\.+]+)|', $this->uastring, $regs)) {
979 $this->brand = 'Microsoft Internet Explorer';
980 $this->version = $regs[2];
981 $this->bot = false;
982 }
983 elseif (preg_match('|MSIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
984 $this->brand = 'Microsoft Internet Explorer';
985 $this->version = $regs[1];
986 $this->bot = false;
987 }
988 elseif (preg_match('|MSPIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
989 $this->brand = 'Microsoft Pocket Internet Explorer';
990 $this->version = $regs[1];
991 $this->bot = false;
992 $this->mobile = true;
993 }
994 elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
995 (strpos($this->uastring, 'compatible') === false) && (strpos($this->uastring, 'Gecko/') === false) &&
996 (intval($regs[1]) < 5)) {
997 $this->brand = 'Netscape';
998 $this->version = $regs[1];
999 if (intval($this->version) == 4) { $this->brand .= ' Communicator'; }
1000 $this->bot = false;
1001 }
1002 elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1003 $this->brand = (strpos($this->uastring, 'compatible') !== false)?'Mozilla-compatible (unknown)':'Mozilla (unknown)';
1004 $this->version = null;
1005 $this->bot = false;
1006 }
1007
1008 $botArray = array('Scooter','Spinne','Vagabondo','Firefly','Scrubby','NG','Pompos','Szukacz','Schmozilla','42_HAL',
1009 'NetResearchServer','LinkWalker','Zeus','W3C_Validator','ZyBorg','Ask Jeeves','ia_archiver',
1010 'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','search.ch',
1011 'appie','larbin','NutchCVS','Webchat','Mediapartners-Google','sitecheck.internetseer.com',
1012 'FavOrg','findlinks','DataCha0s','ichiro','Francis','CoralWebPrx','DoCoMo','Ocelli','Sogou Video',
1013 'Yandex','Yeti','Austronaut-URL-Checker');
1014
1015 if (in_array($this->brand, $botArray)) {
1016 $this->bot = true;
1017 }
1018
1019 if (($this->brand == 'Microsoft Pocket Internet Explorer') ||
1020 (strpos($this->brand, 'BlackBerry') !== false)) {
1021 $this->mobile = true;
1022 }
1023 }
1024
1025 public function getBrand() { return $this->brand; }
1026 public function getVersion() { return $this->version; }
1027
1028 public function getAcceptLanguages() {
1029 if (!isset($this->uadata['accept-languages'])) {
1030 $headers = getAllHeaders();
1031 $accLcomp = explode(',', $headers['Accept-Language']);
1032 $accLang = array();
1033 foreach ($accLcomp as $lcomp) {
1034 if (strlen($lcomp)) {
1035 $ldef = explode(';', $lcomp);
1036 $accLang[$ldef[0]] = (float)((strpos(@$ldef[1],'q=')===0)?substr($ldef[1],2):1);
1037 }
1038 }
1039 $this->uadata['accept-languages'] = $accLang;
1040 }
1041 return $this->uadata['accept-languages'];
1042 }
1043
1044 public function getUAString() { return $this->uastring; }
1045
1046 public function getEngine() {
1047 // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|netfront|unknown
1048 if (!isset($this->uadata['engine'])) {
1049 $this->uadata['engine'] = 'unknown';
1050 $this->uadata['geckodate'] = null;
1051 if (!$this->bot) {
1052 if (preg_match('|Gecko/([0-9\.]+)|', $this->uastring, $regs) && (strpos($this->brand, 'Opera') === false)) {
1053 $this->uadata['engine'] = 'gecko';
1054 // If it looks like a version number, i.e. shorter than 4 chars or has a . in it, it's no date.
1055 if ((strlen($regs[1]) > 4) && (strpos($regs[1], '.') === false)) {
1056 $this->uadata['geckodate'] = $regs[1];
1057 }
1058 else {
1059 $this->uadata['geckodate'] = null;
1060 $this->uadata['eng_version'] = $regs[1];
1061 }
1062 }
1063 elseif (preg_match('|Edge/([0-9\.]+)|', $this->uastring, $regs)) {
1064 $this->uadata['engine'] = 'edgehtml';
1065 $this->uadata['eng_version'] = $regs[1];
1066 }
1067 elseif ((strpos($this->brand, 'Internet Explorer') !== false) || (strpos($this->brand, 'FrontPage') !== false)) {
1068 if ((strpos(strtolower($this->uastring), 'mac') !== false) && (intval($this->getVersion()) >= 5)) {
1069 $this->uadata['engine'] = 'tasman';
1070 }
1071 else {
1072 $this->uadata['engine'] = 'trident';
1073 }
1074 }
1075 elseif (preg_match('|WebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1076 $this->uadata['engine'] = 'webkit';
1077 $this->uadata['eng_version'] = $regs[1];
1078 }
1079 elseif ((strpos($this->brand, 'Konqueror') !== false) || (strpos($this->brand, 'OmniWeb') !== false)) {
1080 $this->uadata['engine'] = 'khtml';
1081 }
1082 elseif (strpos($this->brand, 'Netscape') !== false) {
1083 // non-Gecko Netscape browsers
1084 if (intval($this->version) <= 4) {
1085 $this->uadata['engine'] = 'nscp';
1086 }
1087 elseif (strpos($this->uastring, 'MSIE') !== false) {
1088 $this->uadata['engine'] = 'trident';
1089 }
1090 }
1091 elseif (strpos($this->brand, 'Opera') !== false) {
1092 $this->uadata['engine'] = 'presto';
1093 }
1094 elseif ((strpos($this->brand, 'iTunes') !== false) || (strpos($this->brand, 'nook browser') !== false)) {
1095 $this->uadata['engine'] = 'webkit';
1096 }
1097 elseif (strpos($this->brand, 'Dillo') !== false) {
1098 $this->uadata['engine'] = 'gzilla';
1099 }
1100 elseif ((strpos($this->brand, 'ELinks') !== false) || (strpos($this->brand, 'Links') !== false)) {
1101 $this->uadata['engine'] = 'links';
1102 }
1103 elseif ((strpos($this->brand, 'Lynx') !== false)) {
1104 $this->uadata['engine'] = 'lynx';
1105 }
1106 elseif ((strpos($this->brand, 'ICEbrowser') !== false) || (strpos($this->brand, 'ICE Browser') !== false)) {
1107 $this->uadata['engine'] = 'icestorm';
1108 }
1109 elseif (preg_match('|NetFront/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1110 $this->uadata['engine'] = 'netfront';
1111 $this->uadata['eng_version'] = $regs[1];
1112 }
1113 elseif ((strpos($this->brand, 'PlayStation') !== false) || (strpos($this->brand, 'NetFront') !== false)) {
1114 $this->uadata['engine'] = 'netfront';
1115 }
1116 elseif ((strpos($this->brand, 'Avant') !== false) || (strpos($this->brand, 'Crazy Browser') !== false) ||
1117 (strpos($this->brand, 'AOL') !== false) || (strpos($this->brand, 'MSN') !== false) ||
1118 (strpos($this->brand, 'MyIE2') !== false) || (strpos($this->brand, 'Maxthon') !== false)) {
1119 $this->uadata['engine'] = 'trident';
1120 }
1121 elseif (strpos($this->brand, 'Galeon') !== false) {
1122 $this->uadata['engine'] = 'gecko';
1123 }
1124 elseif (strpos($this->brand, 'WebPro') !== false) {
1125 $this->uadata['engine'] = 'nscp';
1126 }
1127 }
1128 }
1129 return $this->uadata['engine'];
1130 }
1131
1132 public function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); }
1133
1134 public function getEngineVersion() {
1135 if (!isset($this->uadata['eng_version'])) {
1136 $this->uadata['eng_version'] = null;
1137 // getOS() should get the date for us
1138 $this->getOS();
1139 }
1140 return $this->uadata['eng_version'];
1141 }
1142
1143 public function getOS() {
1144 if (!isset($this->uadata['os'])) {
1145 $this->uadata['os'] = null;
1146 if (!$this->bot) {
1147 if ($this->hasEngine('gecko')) {
1148 if (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1149 $this->uadata['os'] = $regs[2].' ('.$regs[3].')';
1150 $this->uadata['lang'] = (strpos($regs[4],'chrome://')===false)?$regs[4]:null;
1151 $this->uadata['eng_version'] = $regs[5];
1152 }
1153 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1154 $this->uadata['os'] = $regs[2];
1155 $this->uadata['lang'] = (strpos($regs[3],'chrome://')===false)?$regs[3]:null;
1156 $this->uadata['eng_version'] = $regs[4];
1157 }
1158 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1159 $this->uadata['os'] = $regs[2];
1160 $this->uadata['lang'] = null;
1161 $this->uadata['eng_version'] = $regs[3];
1162 }
1163 elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); x64; rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1164 $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1165 $this->uadata['lang'] = null;
1166 $this->uadata['eng_version'] = $regs[3];
1167 }
1168 elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1169 $this->uadata['os'] = $regs[2];
1170 $this->uadata['lang'] = (strpos($regs[3],'chrome://')===false)?$regs[3]:null;
1171 $this->uadata['eng_version'] = $regs[4];
1172 }
1173 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
1174 $this->uadata['os'] = $regs[2];
1175 $this->uadata['lang'] = $regs[3];
1176 $this->uadata['eng_version'] = 'M'.$regs[4];
1177 }
1178 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
1179 $this->uadata['os'] = $regs[1];
1180 $this->uadata['lang'] = $regs[2];
1181 $this->uadata['eng_version'] = 'M'.$regs[3];
1182 }
1183 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1184 $this->uadata['os'] = $regs[2];
1185 $this->uadata['lang'] = $regs[3];
1186 $this->uadata['eng_version'] = null;
1187 }
1188 elseif (preg_match('#Mozilla/5.0 \(([^;]+); (WOW64|Mobile|Tablet); rv:([^\);]+)\)#', $this->uastring, $regs)) {
1189 $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1190 $this->uadata['lang'] = null;
1191 $this->uadata['eng_version'] = $regs[3];
1192 $this->mobile = ($regs[2] == 'Mobile');
1193 }
1194 elseif (preg_match('#Mozilla/5.0 \((Mobile|Tablet); [^;]+; rv:([^\);]+)\)#', $this->uastring, $regs)) {
1195 $this->uadata['os'] = 'Firefox OS ('.$regs[1].')';
1196 $this->uadata['lang'] = null;
1197 $this->uadata['eng_version'] = $regs[2];
1198 $this->mobile = ($regs[1] == 'Mobile');
1199 }
1200 elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) {
1201 if ((strpos($regs[2], 'Linux') !== false) && ($regs[1] != 'X11')) {
1202 $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1203 }
1204 else {
1205 $this->uadata['os'] = $regs[2];
1206 }
1207 $this->uadata['lang'] = null;
1208 $this->uadata['eng_version'] = $regs[3];
1209 }
1210 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^\);]+)\)|', $this->uastring, $regs)) {
1211 $this->uadata['os'] = $regs[2];
1212 $this->uadata['lang'] = null;
1213 $this->uadata['eng_version'] = null;
1214 }
1215 elseif (preg_match('#Mozilla/5.0 \((Mobile|Tablet); rv:([^\);]+)\)#', $this->uastring, $regs)) {
1216 $this->uadata['os'] = 'Firefox OS ('.$regs[1].')';
1217 $this->uadata['lang'] = null;
1218 $this->uadata['eng_version'] = $regs[2];
1219 $this->mobile = ($regs[1] == 'Mobile');
1220 }
1221 elseif (preg_match('|Mozilla/5.0 \(([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) {
1222 $this->uadata['os'] = $regs[1];
1223 $this->uadata['lang'] = null;
1224 $this->uadata['eng_version'] = $regs[2];
1225 }
1226 elseif (preg_match('|Mozilla/5.0 Galeon/[^\(]+ \(([^;]+); ([^;]+);[^\)]+\)|', $this->uastring, $regs)) {
1227 $this->uadata['os'] = $regs[2];
1228 $this->uadata['lang'] = null;
1229 $this->uadata['eng_version'] = null;
1230 }
1231 elseif (preg_match('|Debian/|', $this->uastring, $regs)) {
1232 $this->uadata['os'] = 'Debian Linux';
1233 $this->uadata['lang'] = null;
1234 $this->uadata['eng_version'] = null;
1235 }
1236 }
1237 elseif ($this->hasEngine('edgehtml')) {
1238 if (preg_match('#Mozilla/5.0 \(([^;]+); (WOW64|Win64); ([^\);]+)\)#', $this->uastring, $regs)) {
1239 $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1240 }
1241 }
1242 elseif ($this->hasEngine('trident') || $this->hasEngine('tasman')) {
1243 if (preg_match('/Mozilla\/[^\(]+ \((IE [^;]+[^\)]*; )?((?:Mac|Win)[^;]+); ?(Win64|WOW64); ?Trident\/([^;\)]+);/i', $this->uastring, $regs)) {
1244 $this->uadata['eng_version'] = $regs[4];
1245 $this->uadata['os'] = $regs[2].' ('.$regs[3].')';
1246 $this->uadata['lang'] = null;
1247 }
1248 elseif (preg_match('/Mozilla\/[^\(]+ \((IE [^;]+[^\)]*; )?((?:Mac|Win)[^;]+); ?Trident\/([^;\)]+);/i', $this->uastring, $regs)) {
1249 $this->uadata['eng_version'] = $regs[3];
1250 $this->uadata['os'] = $regs[2];
1251 $this->uadata['lang'] = null;
1252 }
1253 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE [^;]+[^\)]*; ?((?:Mac|Win)[^;]+); ?(Win64|WOW64)[^\)]*Trident\/([^;\)]+)[^\)]*\)/i', $this->uastring, $regs)) {
1254 $this->uadata['eng_version'] = $regs[3];
1255 $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1256 $this->uadata['lang'] = null;
1257 }
1258 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE [^;]+[^\)]*; ?((?:Mac|Win)[^;]+); ?[^\)]*Trident\/([^;\)]+)[^\)]*\)/i', $this->uastring, $regs)) {
1259 $this->uadata['eng_version'] = $regs[2];
1260 $this->uadata['os'] = $regs[1];
1261 $this->uadata['lang'] = null;
1262 }
1263 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSP?IE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+); ?(Win64|WOW64)[^\)]*\)/i', $this->uastring, $regs)) {
1264 $this->uadata['eng_version'] = (strpos($this->uastring,'MSPIE')!==false)?null:"ie".$regs[1];
1265 $this->uadata['os'] = $regs[2].' ('.$regs[3].')';
1266 $this->uadata['lang'] = null;
1267 $this->mobile = (strpos($this->uastring,'MSPIE') !== false);
1268 }
1269 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSP?IE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
1270 $this->uadata['eng_version'] = (strpos($this->uastring,'MSPIE')!==false)?null:"ie".$regs[1];
1271 $this->uadata['os'] = $regs[2];
1272 $this->uadata['lang'] = null;
1273 $this->mobile = (strpos($this->uastring,'MSPIE') !== false);
1274 }
1275 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE ([^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
1276 $this->uadata['eng_version'] = "ie".$regs[1];
1277 $this->uadata['os'] = null;
1278 $this->uadata['lang'] = null;
1279 }
1280 elseif (preg_match('/Microsoft Internet Explorer\/[^\s]+ \(((?:Mac|Win)[^;\)]+)\)/i', $this->uastring, $regs)) {
1281 $this->uadata['eng_version'] = "ie".$this->getVersion();
1282 $this->uadata['os'] = $regs[1];
1283 $this->uadata['lang'] = null;
1284 }
1285 elseif (preg_match('/Microsoft Pocket Internet Explorer\/[^\s]+/i', $this->uastring, $regs)) {
1286 $this->uadata['eng_version'] = null;
1287 $this->uadata['os'] = 'Windows CE';
1288 $this->uadata['lang'] = null;
1289 }
1290 }
1291 elseif ($this->hasEngine('khtml')) {
1292 if (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^;]+); ([^;]+); ([^;]+); ([^\);]+)\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
1293 $this->uadata['eng_version'] = strlen($regs[6])?$regs[6]:$regs[1];
1294 $this->uadata['os'] = $regs[2];
1295 $this->uadata['lang'] = $regs[5];
1296 }
1297 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^\);]+)[^\)]*\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
1298 $this->uadata['eng_version'] = strlen($regs[3])?$regs[3]:$regs[1];
1299 $this->uadata['os'] = $regs[2];
1300 $this->uadata['lang'] = null;
1301 }
1302 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; [^;]+; ([^\);]+)\)/i', $this->uastring, $regs)) {
1303 $this->uadata['os'] = $regs[1];
1304 $this->uadata['lang'] = null;
1305 $this->uadata['eng_version'] = null;
1306 }
1307 }
1308 elseif ($this->hasEngine('webkit')) {
1309 if (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^\);]+); ([^\);]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1310 $this->uadata['os'] = $regs[2];
1311 $this->uadata['lang'] = $regs[3];
1312 }
1313 elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^\);]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1314 if (strpos($regs[3], '/') !== false) {
1315 $this->uadata['os'] = $regs[1];
1316 $this->uadata['lang'] = null;
1317 }
1318 else {
1319 $this->uadata['os'] = $regs[2];
1320 $this->uadata['lang'] = $regs[3];
1321 }
1322 }
1323 elseif (preg_match('|Mozilla/5.0 \(([^;]+); Linux; ([^;]+); U; ([^\);]+)\)|', $this->uastring, $regs)) {
1324 $this->uadata['os'] = $regs[2];
1325 $this->uadata['lang'] = $regs[3];
1326 }
1327 elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^\);]+)\)|', $this->uastring, $regs)) {
1328 $this->uadata['os'] = $regs[1];
1329 $this->uadata['lang'] = $regs[2];
1330 }
1331 elseif (preg_match('|Mozilla/5.0 \(Linux; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1332 // (Chrome for) Android - $regs[2] is device
1333 $this->uadata['os'] = $regs[1];
1334 $this->uadata['lang'] = null;
1335 }
1336 elseif (preg_match('|Mozilla/5.0 \(([^\);]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1337 if (($regs[1] == 'X11') || ($regs[1] == 'Macintosh') || ($regs[1] == 'iPhone')) {
1338 $this->uadata['os'] = $regs[2];
1339 }
1340 else {
1341 $this->uadata['os'] = $regs[1];
1342 if ($regs[2] == 'NokiaN9') {
1343 $this->uadata['os'] .= ' Harmattan';
1344 }
1345 }
1346 $this->uadata['lang'] = null;
1347 }
1348 elseif (preg_match('|Mozilla/5.0 \(([^\);]+)\)|', $this->uastring, $regs)) {
1349 $this->uadata['os'] = $regs[1];
1350 $this->uadata['lang'] = null;
1351 }
1352 elseif (preg_match('|Midori/[^\(]+ \((?:X11; )?([^;]+); U; ([^\)]+)\)|i', $this->uastring, $regs)) {
1353 $this->uadata['os'] = $regs[1];
1354 $this->uadata['lang'] = $regs[2];
1355 }
1356 if ($this->brand == 'Silk') {
1357 // For some reason, Amazon spoofs us and tells us it's on MacOS X!
1358 $this->uadata['os'] = 'Android';
1359 }
1360 if (preg_match('| Mobile |', $this->uastring)) {
1361 $this->mobile = true;
1362 }
1363 }
1364 elseif ($this->hasEngine('presto')) {
1365 // Opera < 8
1366 if (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+)[^\)]+\) +\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
1367 $this->uadata['eng_version'] = $this->getVersion();
1368 $this->uadata['os'] = $regs[1];
1369 $this->uadata['lang'] = $regs[2];
1370 }
1371 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;\)]+)[^\)]*\) Opera [^ ]+\s+\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
1372 $this->uadata['eng_version'] = $this->getVersion();
1373 $this->uadata['os'] = $regs[1];
1374 $this->uadata['lang'] = $regs[2];
1375 }
1376 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+\) Opera [^ ]+\s+\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
1377 $this->uadata['eng_version'] = $this->getVersion();
1378 $this->uadata['os'] = $regs[1];
1379 $this->uadata['lang'] = $regs[2];
1380 }
1381 // Opera mini
1382 elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini; ([a-z_-]+); /i', $this->uastring, $regs)) {
1383 $this->uadata['eng_version'] = null;
1384 $this->uadata['os'] = $regs[2];
1385 $this->uadata['lang'] = $regs[3];
1386 }
1387 elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini\/[^;]+; ([a-z_-]+); /i', $this->uastring, $regs)) {
1388 $this->uadata['eng_version'] = $regs[1];
1389 $this->uadata['os'] = $regs[2];
1390 $this->uadata['lang'] = $regs[3];
1391 }
1392 // Opera >= 8
1393 elseif (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+); [^\)]+; ([a-z_-]+)\)/i', $this->uastring, $regs)) {
1394 $this->uadata['eng_version'] = $this->getVersion();
1395 $this->uadata['os'] = $regs[1];
1396 $this->uadata['lang'] = $regs[2];
1397 }
1398 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;]+); ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
1399 $this->uadata['eng_version'] = $this->getVersion();
1400 $this->uadata['os'] = $regs[1];
1401 $this->uadata['lang'] = $regs[2];
1402 }
1403 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
1404 $this->uadata['eng_version'] = $this->getVersion();
1405 $this->uadata['os'] = $regs[1];
1406 $this->uadata['lang'] = $regs[2];
1407 }
1408 // Opera 9 Firefox-spoofing
1409 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+); rv:([^\);]+)\) Gecko\/\d+ Firefox\/[0-9a-zA-Z\.+]+ Opera [^ ]+/i', $this->uastring, $regs)) {
1410 $this->uadata['eng_version'] = $this->getVersion();
1411 $this->uadata['os'] = $regs[1];
1412 $this->uadata['lang'] = $regs[2];
1413 }
1414 if (preg_match('| Mobi|', $this->uastring)) {
1415 $this->mobile = true;
1416 }
1417 }
1418 elseif ($this->hasEngine('nscp')) {
1419 if (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(X11; [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
1420 $this->uadata['eng_version'] = $regs[1];
1421 $this->uadata['os'] = $regs[3];
1422 $this->uadata['lang'] = $regs[2];
1423 }
1424 elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
1425 $this->uadata['eng_version'] = $regs[1];
1426 $this->uadata['os'] = $regs[3];
1427 $this->uadata['lang'] = $regs[2];
1428 }
1429 elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+)[^\(]+\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
1430 $this->uadata['eng_version'] = $regs[1];
1431 $this->uadata['os'] = $regs[2];
1432 $this->uadata['lang'] = null;
1433 }
1434 }
1435 elseif ($this->hasEngine('gzilla')) {
1436 $this->uadata['eng_version'] = $this->getVersion();
1437 $this->uadata['os'] = null;
1438 $this->uadata['lang'] = null;
1439 }
1440 elseif ($this->hasEngine('links')) {
1441 if (preg_match('/E?Links[^\(]+\([^;]+; ([^;]+)[^\)]+\)/i', $this->uastring, $regs)) {
1442 $this->uadata['eng_version'] = null;
1443 $this->uadata['os'] = $regs[1];
1444 $this->uadata['lang'] = null;
1445 }
1446 }
1447 elseif ($this->hasEngine('lynx')) {
1448 $this->uadata['eng_version'] = $this->getVersion();
1449 $this->uadata['os'] = null;
1450 $this->uadata['lang'] = null;
1451 }
1452 elseif ($this->hasEngine('icestorm')) {
1453 if (preg_match('/ICE Browser\/v?([0-9a-zA-Z\._+]+) \(Java [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
1454 $this->uadata['eng_version'] = str_replace('_', '.', $regs[1]);
1455 $this->uadata['os'] = $regs[2];
1456 $this->uadata['lang'] = null;
1457 }
1458 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\).* ICEbrowser\/([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) {
1459 $this->uadata['eng_version'] = $regs[3];
1460 $this->uadata['os'] = $regs[1];
1461 $this->uadata['lang'] = $regs[2];
1462 }
1463 }
1464 else {
1465 $this->uadata['eng_version'] = null;
1466 $this->uadata['lang'] = null;
1467 if (preg_match('/AmigaOS/i', $this->uastring, $regs)) {
1468 $this->uadata['os'] = 'AmigaOS';
1469 }
1470 if (preg_match('/Commodore 64/i', $this->uastring, $regs)) {
1471 $this->uadata['os'] = 'Commodore 64';
1472 }
1473 elseif (preg_match('/curl\/[^\(]+\(([^\);]+)/i', $this->uastring, $regs)) {
1474 $this->uadata['os'] = $regs[1];
1475 }
1476 elseif (preg_match('/NCSA[_ ]Mosaic\/[^\(]+\((?:.*;)?([^\);]+)/i', $this->uastring, $regs)) {
1477 $this->uadata['os'] = trim($regs[1]);
1478 }
1479 elseif (preg_match('/iCab.*(Mac[^\);]+).*?\)/i', $this->uastring, $regs)) {
1480 $this->uadata['os'] = trim($regs[1]);
1481 }
1482 elseif (preg_match('/SymbianOS\/([^ ]+)/i', $this->uastring, $regs)) {
1483 $this->uadata['os'] = 'SymbianOS '.$regs[1];
1484 }
1485 }
1486 if ($this->uadata['os'] == 'Win 9x 4.90') { $this->uadata['os'] = 'Windows ME'; }
1487 elseif ($this->uadata['os'] == 'WinNT4.0') { $this->uadata['os'] = 'Windows NT 4.0'; }
1488 elseif ($this->uadata['os'] == 'Windows NT 5.0') { $this->uadata['os'] = 'Windows 2000'; }
1489 elseif ($this->uadata['os'] == 'Windows NT 5.1') { $this->uadata['os'] = 'Windows XP'; }
1490 elseif ($this->uadata['os'] == 'Windows NT 5.1 (Win64)') { $this->uadata['os'] = 'Windows XP (64bit)'; }
1491 elseif ($this->uadata['os'] == 'Windows NT 5.1 (WOW64)') { $this->uadata['os'] = 'Windows XP (64bit)'; }
1492 elseif ($this->uadata['os'] == 'Windows NT 5.2') { $this->uadata['os'] = 'Windows 2003'; }
1493 elseif ($this->uadata['os'] == 'Windows NT 5.2 x64') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1494 elseif ($this->uadata['os'] == 'Windows NT 5.2 (Win64)') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1495 elseif ($this->uadata['os'] == 'Windows NT 5.2 (WOW64)') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1496 elseif ($this->uadata['os'] == 'Windows NT 6.0') { $this->uadata['os'] = 'Windows Vista'; }
1497 elseif ($this->uadata['os'] == 'Windows NT 6.0 (Win64)') { $this->uadata['os'] = 'Windows Vista (64bit)'; }
1498 elseif ($this->uadata['os'] == 'Windows NT 6.0 (WOW64)') { $this->uadata['os'] = 'Windows Vista (64bit)'; }
1499 elseif ($this->uadata['os'] == 'Windows NT 6.1') { $this->uadata['os'] = 'Windows 7'; }
1500 elseif ($this->uadata['os'] == 'Windows NT 6.1 (Win64)') { $this->uadata['os'] = 'Windows 7 (64bit)'; }
1501 elseif ($this->uadata['os'] == 'Windows NT 6.1 (WOW64)') { $this->uadata['os'] = 'Windows 7 (64bit)'; }
1502 elseif ($this->uadata['os'] == 'Windows NT 6.2') { $this->uadata['os'] = 'Windows 8'; }
1503 elseif ($this->uadata['os'] == 'Windows NT 6.2 (Win64)') { $this->uadata['os'] = 'Windows 8 (64bit)'; }
1504 elseif ($this->uadata['os'] == 'Windows NT 6.2 (WOW64)') { $this->uadata['os'] = 'Windows 8 (64bit)'; }
1505 elseif ($this->uadata['os'] == 'Windows NT 6.3') { $this->uadata['os'] = 'Windows 8.1'; }
1506 elseif ($this->uadata['os'] == 'Windows NT 6.3 (Win64)') { $this->uadata['os'] = 'Windows 8.1 (64bit)'; }
1507 elseif ($this->uadata['os'] == 'Windows NT 6.3 (WOW64)') { $this->uadata['os'] = 'Windows 8.1 (64bit)'; }
1508 elseif ($this->uadata['os'] == 'Windows NT 6.4') { $this->uadata['os'] = 'Windows 10'; }
1509 elseif ($this->uadata['os'] == 'Windows NT 6.4 (Win64)') { $this->uadata['os'] = 'Windows 10 (64bit)'; }
1510 elseif ($this->uadata['os'] == 'Windows NT 6.4 (WOW64)') { $this->uadata['os'] = 'Windows 10 (64bit)'; }
1511 elseif ($this->uadata['os'] == 'Windows NT 10.0') { $this->uadata['os'] = 'Windows 10'; }
1512 elseif ($this->uadata['os'] == 'Windows NT 10.0 (Win64)') { $this->uadata['os'] = 'Windows 10 (64bit)'; }
1513 elseif ($this->uadata['os'] == 'Windows NT 10.0 (WOW64)') { $this->uadata['os'] = 'Windows 10 (64bit)'; }
1514 elseif ($this->uadata['os'] == 'Win95') { $this->uadata['os'] = 'Windows 95'; }
1515 elseif ($this->uadata['os'] == 'Win98') { $this->uadata['os'] = 'Windows 98'; }
1516 elseif ($this->uadata['os'] == 'WinNT') { $this->uadata['os'] = 'Windows NT'; }
1517 elseif ($this->uadata['os'] == 'Win32') { $this->uadata['os'] = 'Windows (32bit)'; }
1518 elseif ($this->uadata['os'] == 'Win64') { $this->uadata['os'] = 'Windows (64bit)'; }
1519 elseif (preg_match('/iPhone OS ([\d_]+)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'iOS '.str_replace('_', '.', $regs[1]); }
1520 elseif (preg_match('/Mac ?OS ?X/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; }
1521 elseif (preg_match('/Mac_P(ower|)PC/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; }
1522 elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
1523 elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
1524 elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
1525 elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
1526 elseif (preg_match('/(?:web|hpw)OS\/([0-9a-zA-Z\._+]+)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'webOS '.$regs[1]; }
1527 elseif (preg_match('/Android \(Linux (.+)\)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'Android '.$regs[1]; }
1528 elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
1529 elseif (preg_match('/SymbianOS[\/ ]([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) { $this->uadata['os'] = 'SymbianOS '.$regs[1]; }
1530 elseif (preg_match('/Symbian ?OS/i', $this->uadata['os'])) { $this->uadata['os'] = 'SymbianOS'; }
1531
1532 if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
1533 elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
1534 elseif (strpos($this->uadata['os'], 'iOS') !== false) { $this->uadata['platform'] = 'Macintosh'; }
1535 elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
1536 elseif (strpos($this->uadata['os'], 'MeeGo') !== false) { $this->uadata['platform'] = 'Linux'; }
1537 elseif (strpos($this->uadata['os'], 'webOS') !== false) { $this->uadata['platform'] = 'Linux'; }
1538 elseif (strpos($this->uadata['os'], 'Android') !== false) { $this->uadata['platform'] = 'Android'; }
1539 elseif (strpos($this->uadata['os'], 'Firefox OS') !== false) { $this->uadata['platform'] = 'Firefox OS'; }
1540 elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
1541 elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
1542 elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
1543 elseif (strpos($this->uadata['os'], 'BePC') !== false) { $this->uadata['platform'] = 'BeOS'; }
1544 elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
1545 elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
1546 elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
1547 elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
1548 elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
1549 elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
1550 elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
1551 elseif (strpos($this->uadata['os'], 'webOS') !== false) { $this->uadata['platform'] = 'webOS'; }
1552 elseif (strpos($this->uadata['os'], 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; }
1553 elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
1554 elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
1555 elseif (strpos($this->uadata['os'], 'OS/2') !== false) { $this->uadata['platform'] = 'OS/2'; }
1556 elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
1557 elseif (strpos($this->uadata['os'], 'BlackBerry') !== false) { $this->uadata['platform'] = 'BlackBerry'; }
1558 elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->uadata['platform'] = 'Nintendo'; }
1559 elseif (strpos($this->uadata['os'], 'Wii') !== false) { $this->uadata['platform'] = 'Nintendo'; }
1560 elseif (strpos($this->uadata['os'], 'Nintendo') !== false) { $this->uadata['platform'] = 'Nintendo'; }
1561 elseif (strpos($this->uadata['os'], 'J2ME') !== false) { $this->uadata['platform'] = 'Java'; }
1562 elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
1563 elseif (strpos($this->uadata['os'], 'mingw') !== false) { $this->uadata['platform'] = 'Windows'; }
1564 else { $this->uadata['platform'] = $this->uadata['os']; }
1565
1566 if (strpos($this->uadata['os'], 'Windows Phone OS') !== false) { $this->mobile = true; }
1567 elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->mobile = true; }
1568
1569 $this->uadata['lang'] = str_replace('_', '-', @$this->uadata['lang']);
1570 }
1571 }
1572 return $this->uadata['os'];
1573 }
1574
1575 public function getPlatform() {
1576 if (!isset($this->uadata['platform'])) {
1577 $this->uadata['platform'] = null;
1578 // getOS() should get the date for us
1579 $this->getOS();
1580 }
1581 return $this->uadata['platform'];
1582 }
1583
1584 public function getLanguage() {
1585 if (!isset($this->uadata['lang'])) {
1586 $this->uadata['lang'] = null;
1587 // getOS() should get the date for us
1588 $this->getOS();
1589 }
1590 return $this->uadata['lang'];
1591 }
1592
1593 public function getGeckoDate() {
1594 if (!isset($this->uadata['geckodate'])) {
1595 $this->uadata['geckodate'] = null;
1596 // getEngine() should get the date for us
1597 $this->getEngine();
1598 }
1599 return $this->uadata['geckodate'];
1600 }
1601
1602 public function getGeckoTime() {
1603 if (!isset($this->uadata['geckotime'])) {
1604 $this->uadata['geckotime'] = null;
1605 if (!is_null($this->getGeckoDate())) {
1606 $use_time = (strlen($this->getGeckoDate()) > 8);
1607 $gd_str = substr($this->getGeckoDate(),0,4).'-'.substr($this->getGeckoDate(),4,2).'-'.substr($this->getGeckoDate(),6,2);
1608 if ($use_time) {
1609 $gd_str .= substr($this->getGeckoDate(),8,2).':00';
1610 $old_tz = date_default_timezone_get();
1611 date_default_timezone_set("America/Los_Angeles");
1612 }
1613 $this->uadata['geckotime'] = strtotime($gd_str);
1614 if ($use_time) { date_default_timezone_set($old_tz); }
1615 }
1616 }
1617 return $this->uadata['geckotime'];
1618 }
1619
1620 public function isBot() { return $this->bot; }
1621
1622 public function isMobile() {
1623 if (!isset($this->uadata['os'])) {
1624 // getOS() makes sure that also the mobile tag is set correctly
1625 $this->getOS();
1626 }
1627 return $this->mobile;
1628 }
1629
1630 public function isns() {
1631 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1632 return (strpos($this->brand, 'Netscape') !== false);
1633 }
1634 public function isns4() {
1635 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1636 return ((strpos($this->brand, 'Netscape') !== false) && (intval($this->version) == 4));
1637 }
1638 public function isie() {
1639 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1640 return $this->hasEngine('trident');
1641 }
1642 public function geckodate() {
1643 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1644 return (!is_null($this->getGeckoDate())?$this->getGeckoDate():0);
1645 }
1646 public function geckobased() {
1647 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1648 return $this->hasEngine('gecko');
1649 }
1650 public function khtmlbased() {
1651 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1652 return $this->hasEngine('khtml');
1653 }
1654}
1655?>