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
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 userAgent([$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 // function getBrand()
57 // returns the User Agent Brand Name
59 // function getVersion()
60 // returns the User Agent version
62 // 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 // function getUAString()
67 // returns the full User Agent string
69 // 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|unkown
73 // function hasEngine($rnd_engine)
74 // returns true if the given rendering engine was detected
76 // 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
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 // function getPlatform()
85 // returns a string telling the detected OS platform, null if we can't detect
86 // one of windows|linux|mac|solaris|unkown
88 // function getLanguage() {
89 // returns a string telling the detected browser UI language, null if we can't detect
90 // should be an ISO code
93 // returns true if User Agent seems to be a bot
95 // *** functions that only return useable info for some agents ***
97 // function getGeckoDate()
98 // returns the Gecko date for Gecko-based browsers, null for others
100 // *** functions for compat to older versions of this class ***
103 // returns true if User Agent seems to be Netscape brand, false if not
105 // returns true if User Agent seems to be Netscape Communicator 4.x, false if not
107 // returns true if User Agent seems to be a version of Internet Exploder, false if not
108 // function geckobased()
109 // returns true if User Agent seems to be a Gecko-based browser, false if not
110 // function geckodate()
111 // returns the Gecko date when it's a Gecko-based browser, 0 if not
112 // function khtmlbased()
113 // returns true if User Agent seems to be a KHTML-based browser, false if not
115 // collection of some known User Agent Strings:
116 // *** see testbed/ua_list_raw.txt ***
117 // *** see also http://www.pgts.com.au/pgtsj/pgtsj0208c.html ***
123 var $uadata = array();
125 function userAgent($ua_string = '') {
126 // *** constructor ***
127 if (strlen($ua_string)) {
128 $this->uastring = $ua_string;
131 // read raw UA string
132 $this->uastring = $_SERVER['HTTP_USER_AGENT'];
135 // get UA brand and version
136 $this->brand = 'Unknown'; $this->version = null;
137 // find reasonable defaults
138 if (preg_match('|([0-9a-zA-Z\.:()_ -]+)/([0-9a-zA-Z\._+-]+)|', $this->uastring, $regs)) {
139 $this->brand = trim($regs[1]);
140 $this->version = $regs[2];
142 elseif (preg_match('|^([a-zA-Z\._ -]+)[_ -][vV]?([0-9][0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
143 $this->brand = trim($regs[1]);
144 $this->version = $regs[2];
146 elseif (preg_match('|^([a-zA-Z\._ -]+)|', $this->uastring, $regs)) {
147 $this->brand = trim($regs[1]);
148 $this->version = null;
150 $this->bot = (strpos(strtolower($this->brand), 'bot') !== false)
151 || (strpos(strtolower($this->brand), 'crawler') !== false)
152 || (strpos(strtolower($this->brand), 'spider') !== false);
154 // search for any real and/or special UAs
155 if (preg_match('|Netscape6/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
156 $this->brand = 'Netscape';
157 $this->version = $regs[1];
160 elseif (preg_match('|Netscape/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
161 $this->brand = 'Netscape';
162 $this->version = $regs[1];
165 elseif (preg_match('|Chimera/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
166 $this->brand = 'Chimera';
167 $this->version = $regs[1];
170 elseif (preg_match('|Camino/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
171 $this->brand = 'Camino';
172 $this->version = $regs[1];
175 elseif (preg_match('|Phoenix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
176 $this->brand = 'Phoenix';
177 $this->version = $regs[1];
180 elseif (preg_match('|Mozilla Firebird/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
181 $this->brand = 'Mozilla Firebird';
182 $this->version = $regs[1];
185 elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
186 $this->brand = 'Firefox';
187 $this->version = $regs[1];
190 elseif (preg_match('|SeaMonkey/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
191 $this->brand = 'SeaMonkey';
192 $this->version = $regs[1];
195 elseif (preg_match('|Galeon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
196 $this->brand = 'Galeon';
197 $this->version = $regs[1];
200 elseif (preg_match('|Epiphany/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
201 $this->brand = 'Epiphany';
202 $this->version = $regs[1];
205 elseif (preg_match('|K-Meleon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
206 $this->brand = 'K-Meleon';
207 $this->version = $regs[1];
210 elseif (preg_match('|AOL[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
211 $this->brand = 'AOL';
212 $this->version = $regs[1];
215 elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
216 $this->brand = 'Mozilla';
217 $this->version = $regs[1];
220 elseif (preg_match('|m([0-9]+)\)|', $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
221 $this->brand = 'Mozilla';
222 $this->version = 'M'.$regs[1];
225 elseif (preg_match('|Opera[ /]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
226 $this->brand = 'Opera';
227 $this->version = $regs[1];
230 elseif (preg_match('|OmniWeb/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
231 $this->brand = 'OmniWeb';
232 $this->version = $regs[1];
235 elseif (preg_match('|Konqueror/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
236 $this->brand = 'Konqueror';
237 $this->version = $regs[1];
240 elseif (preg_match('|Safari/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
241 $this->brand = 'Safari';
242 $this->version = $regs[1];
245 elseif (preg_match('|AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
246 $this->brand = 'AppleWebKit';
247 $this->version = $regs[1];
250 elseif (preg_match('|MSFrontPage/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
251 $this->brand = 'Microsoft FrontPage';
252 $this->version = $regs[1];
255 elseif (preg_match('|iCab[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
256 $this->brand = 'iCab';
257 $this->version = $regs[1];
260 elseif (preg_match('|IBrowse[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
261 $this->brand = 'IBrowse';
262 $this->version = $regs[1];
265 elseif (preg_match('|Configuration/CLDC-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
266 $this->brand = 'CLDC';
267 $this->version = $regs[1];
270 elseif (preg_match('|UP.Browser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
271 $this->brand = 'UP.Browser';
272 $this->version = $regs[1];
275 elseif (preg_match('|ELinks \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
276 $this->brand = 'ELinks';
277 $this->version = $regs[1];
280 elseif (preg_match('|Links \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
281 $this->brand = 'Links';
282 $this->version = $regs[1];
285 elseif (preg_match('|wget[/ ]([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
286 $this->brand = 'wget';
287 $this->version = $regs[1];
290 elseif (preg_match('|ZyBorg/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
291 $this->brand = 'ZyBorg';
292 $this->version = $regs[1];
295 elseif (preg_match('|Googlebot/?([0-9a-zA-Z\.+]+)?|', $this->uastring, $regs)) {
296 $this->brand = 'Googlebot';
297 $this->version = $regs[1];
300 elseif (preg_match('|Ask Jeeves/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
301 $this->brand = 'Ask Jeeves';
302 $this->version = $regs[1];
305 elseif (preg_match('|Slurp|', $this->uastring, $regs)) {
306 $this->brand = 'Slurp';
307 $this->version = null;
310 elseif (preg_match('|Gulper Web Bot ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
311 $this->brand = 'Gulper Web Bot';
312 $this->version = $regs[1];
315 elseif (preg_match('|HTTrack ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
316 $this->brand = 'HTTrack';
317 $this->version = $regs[1];
320 elseif (preg_match('|([0-9a-zA-Z\.+]+)_AC-Plug|', $this->uastring, $regs)) {
321 $this->brand = 'AC-Plug';
322 $this->version = $regs[1];
325 elseif (preg_match('|^Internet Explorer 5.5|', $this->uastring)) {
326 $this->brand = 'Unknown bot (IE5.5)';
327 $this->version = null;
330 elseif (preg_match('|^Mozilla[\s ]*$|', $this->uastring)) {
331 $this->brand = 'Unknown bot (Mozilla)';
332 $this->version = null;
335 elseif (preg_match('|http://www.almaden.ibm.com/cs/crawler|', $this->uastring)) {
336 $this->brand = 'almaden crawler';
337 $this->version = null;
340 elseif (preg_match('|B-l-i-t-z-B-O-T|', $this->uastring) || preg_match('|B l i t z B O T @ t r i c u s . n e t|', $this->uastring)) {
341 $this->brand = 'BlitzBOT';
342 $this->version = null;
345 elseif (preg_match('|sitecheck.internetseer.com|', $this->uastring)) {
346 $this->brand = 'internetseer';
347 $this->version = null;
350 elseif (preg_match('|Girafabot|', $this->uastring)) {
351 $this->brand = 'Girafabot';
352 $this->version = null;
355 elseif (preg_match('|efp@gmx.net|', $this->uastring)) {
356 $this->brand = 'efp';
357 $this->version = null;
360 elseif (preg_match('|42_HAL|', $this->uastring)) {
361 $this->brand = '42_HAL';
362 $this->version = null;
365 elseif (preg_match('|Baiduspider|i', $this->uastring)) {
366 $this->brand = 'BaiDuSpider';
367 $this->version = null;
370 elseif (preg_match('|Indy Library|', $this->uastring)) {
371 $this->brand = 'Indy Library';
372 $this->version = null;
375 elseif (preg_match('|^Firefly|', $this->uastring)) {
376 // comes here with correct value but would be detected as MSIE
378 elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
379 $this->brand = 'Steganos Internet Anonym';
380 $this->version = $regs[1];
383 elseif (preg_match('|Avant Browser[^/]|', $this->uastring)) {
384 $this->brand = 'Avant Browser';
385 $this->version = null;
388 elseif (preg_match('|Maxthon|', $this->uastring)) {
389 $this->brand = 'Maxthon';
390 $this->version = null;
393 elseif (preg_match('|MyIE2|', $this->uastring)) {
394 $this->brand = 'MyIE2';
395 $this->version = null;
398 elseif (preg_match('|Crazy Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
399 $this->brand = 'Crazy Browser';
400 $this->version = $regs[1];
403 elseif (preg_match('|AvantGo ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
404 $this->brand = 'AvantGo';
405 $this->version = $regs[1];
408 elseif (preg_match('|MSN ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
409 $this->brand = 'MSN';
410 $this->version = $regs[1];
413 elseif (preg_match('|MS FrontPage ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
414 $this->brand = 'Microsoft FrontPage';
415 $this->version = $regs[1];
418 elseif (preg_match('|MSIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
419 $this->brand = 'Microsoft Internet Explorer';
420 $this->version = $regs[1];
423 elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) && (strpos($this->uastring, 'compatible;') === false) && (strpos($this->uastring, 'Gecko/') === false)) {
424 $this->brand = 'Netscape';
425 $this->version = $regs[1];
426 if (intval($this->version) == 4) { $this->brand .= ' Communicator'; }
429 elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) && (strpos($this->uastring, 'compatible;') !== false)) {
430 $this->brand = 'Mozilla-compatible (unknown)';
431 $this->version = null;
435 $botArray = array('Scooter','Spinne','Vagabondo','Firefly','Scrubby','NG','Pompos','Szukacz','ASPseek',
436 'NetResearchServer','LinkWalker','Zeus','W3C_Validator','ZyBorg','Ask Jeeves','ia_archiver',
437 'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','search.ch',
438 'appie','larbin','NutchCVS','ObjectsSearch','Webchat','Mediapartners-Google','Schmozilla',
439 'FavOrg','findlinks','DataCha0s','','','','','','','','','');
441 if (in_array($this->brand, $botArray)) {
446 function getBrand() { return $this->brand; }
447 function getVersion() { return $this->version; }
449 function getAcceptLanguages() {
450 if (!isset($this->uadata['accept-languages'])) {
451 $headers = getAllHeaders();
452 $accLcomp = explode(',', $headers['Accept-Language']);
454 foreach ($accLcomp as $lcomp) {
455 if (strlen($lcomp)) {
456 $ldef = explode(';', $lcomp);
457 $accLang[$ldef[0]] = (float)((strpos(@$ldef[1],'q=')===0)?substr($ldef[1],2):1);
460 $this->uadata['accept-languages'] = $accLang;
462 return $this->uadata['accept-languages'];
465 function getUAString() { return $this->uastring; }
467 function getEngine() {
468 // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|unkown
469 if (!isset($this->uadata['engine'])) {
470 $this->uadata['engine'] = 'unkown';
471 $this->uadata['geckodate'] = null;
472 if (preg_match('|Gecko/([0-9]+)|', $this->uastring, $regs)) {
473 $this->uadata['engine'] = 'gecko';
474 $this->uadata['geckodate'] = $regs[1];
476 elseif ((strpos($this->brand, 'Internet Explorer') !== false) || (strpos($this->brand, 'FrontPage') !== false)) {
477 if ((strpos(strtolower($this->uastring), 'mac') !== false) && (intval($this->getVersion()) >= 5)) {
478 $this->uadata['engine'] = 'tasman';
481 $this->uadata['engine'] = 'trident';
484 elseif ((strpos($this->brand, 'Konqueror') !== false) || (strpos($this->brand, 'Safari') !== false) || (strpos($this->brand, 'AppleWebKit') !== false) || (strpos($this->brand, 'OmniWeb') !== false)) {
485 $this->uadata['engine'] = 'khtml';
487 elseif (strpos($this->brand, 'Netscape') !== false) {
488 // non-Gecko Netscape browsers
489 if (intval($this->version) <= 4) {
490 $this->uadata['engine'] = 'nscp';
492 elseif (strpos($this->uastring, 'MSIE') !== false) {
493 $this->uadata['engine'] = 'trident';
496 elseif (strpos($this->brand, 'Opera') !== false) {
497 $this->uadata['engine'] = 'presto';
499 elseif (strpos($this->brand, 'Dillo') !== false) {
500 $this->uadata['engine'] = 'gzilla';
502 elseif ((strpos($this->brand, 'ELinks') !== false) || (strpos($this->brand, 'Links') !== false)) {
503 $this->uadata['engine'] = 'links';
505 elseif ((strpos($this->brand, 'Avant') !== false) || (strpos($this->brand, 'Crazy Browser') !== false) ||
506 (strpos($this->brand, 'AOL') !== false) || (strpos($this->brand, 'MSN') !== false) ||
507 (strpos($this->brand, 'MyIE2') !== false) || (strpos($this->brand, 'Maxthon') !== false)) {
508 $this->uadata['engine'] = 'trident';
510 elseif (strpos($this->brand, 'Galeon') !== false) {
511 $this->uadata['engine'] = 'gecko';
514 return $this->uadata['engine'];
517 function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); }
519 function getEngineVersion() {
520 if (!isset($this->uadata['eng_version'])) {
521 $this->uadata['eng_version'] = null;
522 // getOS() should get the date for us
525 return $this->uadata['eng_version'];
529 if (!isset($this->uadata['os'])) {
530 $this->uadata['os'] = null;
531 if ($this->hasEngine('gecko')) {
532 if (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
533 $this->uadata['os'] = $regs[2];
534 $this->uadata['lang'] = (strpos($regs[3],'chrome://')===false)?$regs[3]:null;
535 $this->uadata['eng_version'] = $regs[4];
537 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
538 $this->uadata['os'] = $regs[2];
539 $this->uadata['lang'] = null;
540 $this->uadata['eng_version'] = $regs[3];
542 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
543 $this->uadata['os'] = $regs[2];
544 $this->uadata['lang'] = $regs[3];
545 $this->uadata['eng_version'] = 'M'.$regs[4];
547 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
548 $this->uadata['os'] = $regs[1];
549 $this->uadata['lang'] = $regs[2];
550 $this->uadata['eng_version'] = 'M'.$regs[3];
552 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
553 $this->uadata['os'] = $regs[2];
554 $this->uadata['lang'] = $regs[3];
555 $this->uadata['eng_version'] = null;
557 elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) {
558 $this->uadata['os'] = $regs[2];
559 $this->uadata['lang'] = null;
560 $this->uadata['eng_version'] = $regs[3];
562 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^\);]+)\)|', $this->uastring, $regs)) {
563 $this->uadata['os'] = $regs[2];
564 $this->uadata['lang'] = null;
565 $this->uadata['eng_version'] = null;
567 elseif (preg_match('|Mozilla/5.0 Galeon/[^\(]+ \(([^;]+); ([^;]+);[^\)]+\)|', $this->uastring, $regs)) {
568 $this->uadata['os'] = $regs[2];
569 $this->uadata['lang'] = null;
570 $this->uadata['eng_version'] = null;
572 elseif (preg_match('|Debian/|', $this->uastring, $regs)) {
573 $this->uadata['os'] = 'Debian Linux';
574 $this->uadata['lang'] = null;
575 $this->uadata['eng_version'] = null;
578 elseif ($this->hasEngine('trident') || $this->hasEngine('tasman')) {
579 if (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
580 $this->uadata['eng_version'] = $regs[1];
581 $this->uadata['os'] = $regs[2];
582 $this->uadata['lang'] = null;
584 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE ([^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
585 $this->uadata['eng_version'] = $regs[1];
586 $this->uadata['os'] = null;
587 $this->uadata['lang'] = null;
590 elseif ($this->hasEngine('khtml')) {
591 if (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^;]+); ([^;]+); ([^;]+); ([^\);]+)\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
592 $this->uadata['eng_version'] = strlen($regs[6])?$regs[6]:$regs[1];
593 $this->uadata['os'] = $regs[2];
594 $this->uadata['lang'] = $regs[5];
596 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^\);]+)[^\)]*\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
597 $this->uadata['eng_version'] = strlen($regs[3])?$regs[3]:$regs[1];
598 $this->uadata['os'] = $regs[2];
599 $this->uadata['lang'] = null;
601 elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
602 $this->uadata['os'] = $regs[2];
603 $this->uadata['lang'] = $regs[3];
604 $this->uadata['eng_version'] = null;
606 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; [^;]+; ([^\);]+)\)/i', $this->uastring, $regs)) {
607 $this->uadata['os'] = $regs[1];
608 $this->uadata['lang'] = null;
609 $this->uadata['eng_version'] = null;
612 elseif ($this->hasEngine('presto')) {
613 if (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+)[^\)]+\) +\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
614 $this->uadata['eng_version'] = $this->getVersion();
615 $this->uadata['os'] = $regs[1];
616 $this->uadata['lang'] = $regs[2];
618 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;\)]+)[^\)]*\) Opera [^ ]+ +\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
619 $this->uadata['eng_version'] = $this->getVersion();
620 $this->uadata['os'] = $regs[1];
621 $this->uadata['lang'] = $regs[2];
623 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+\) Opera [^ ]+ \[([a-z_-]+)\]/i', $this->uastring, $regs)) {
624 $this->uadata['eng_version'] = $this->getVersion();
625 $this->uadata['os'] = $regs[1];
626 $this->uadata['lang'] = $regs[2];
629 elseif (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+); [^\)]+; ([a-z_-]+)\)/i', $this->uastring, $regs)) {
630 $this->uadata['eng_version'] = $this->getVersion();
631 $this->uadata['os'] = $regs[1];
632 $this->uadata['lang'] = $regs[2];
634 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;]+); ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
635 $this->uadata['eng_version'] = $this->getVersion();
636 $this->uadata['os'] = $regs[1];
637 $this->uadata['lang'] = $regs[2];
639 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
640 $this->uadata['eng_version'] = $this->getVersion();
641 $this->uadata['os'] = $regs[1];
642 $this->uadata['lang'] = $regs[2];
645 elseif ($this->hasEngine('nscp')) {
646 if (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(X11; [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
647 $this->uadata['eng_version'] = $regs[1];
648 $this->uadata['os'] = $regs[3];
649 $this->uadata['lang'] = $regs[2];
651 elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
652 $this->uadata['eng_version'] = $regs[1];
653 $this->uadata['os'] = $regs[3];
654 $this->uadata['lang'] = $regs[2];
657 elseif ($this->hasEngine('gzilla')) {
658 $this->uadata['eng_version'] = $this->getVersion();
659 $this->uadata['os'] = null;
660 $this->uadata['lang'] = null;
662 elseif ($this->hasEngine('links')) {
663 if (preg_match('/E?Links[^\(]+\([^;]+; ([^;]+)[^\)]+\)/i', $this->uastring, $regs)) {
664 $this->uadata['eng_version'] = null;
665 $this->uadata['os'] = $regs[1];
666 $this->uadata['lang'] = null;
670 $this->uadata['eng_version'] = null;
671 $this->uadata['lang'] = null;
672 if (preg_match('/AmigaOS/i', $this->uastring, $regs)) {
673 $this->uadata['os'] = 'AmigaOS';
675 elseif (preg_match('/curl\/[^\(]+\(([^\);]+)/i', $this->uastring, $regs)) {
676 $this->uadata['os'] = $regs[1];
678 elseif (preg_match('/NCSA[_ ]Mosaic\/[^\(]+\((?:.*;)?([^\);]+)/i', $this->uastring, $regs)) {
679 $this->uadata['os'] = trim($regs[1]);
681 elseif (preg_match('/iCab.*(Mac[^\);]+).*?\)/i', $this->uastring, $regs)) {
682 $this->uadata['os'] = trim($regs[1]);
684 elseif (preg_match('/SymbianOS\/([^ ]+)/i', $this->uastring, $regs)) {
685 $this->uadata['os'] = 'SymbianOS '.$regs[1];
688 if ($this->uadata['os'] == 'Win 9x 4.90') { $this->uadata['os'] = 'Windows ME'; }
689 elseif ($this->uadata['os'] == 'WinNT4.0') { $this->uadata['os'] = 'Windows ME'; }
690 elseif ($this->uadata['os'] == 'Windows NT 5.0') { $this->uadata['os'] = 'Windows 2000'; }
691 elseif ($this->uadata['os'] == 'Windows NT 5.1') { $this->uadata['os'] = 'Windows XP'; }
692 elseif ($this->uadata['os'] == 'Windows NT 5.2') { $this->uadata['os'] = 'Windows 2003'; }
693 elseif ($this->uadata['os'] == 'Windows NT 5.2 x64') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
694 elseif ($this->uadata['os'] == 'Windows NT 6.0') { $this->uadata['os'] = 'Windows Vista'; }
695 elseif ($this->uadata['os'] == 'Win95') { $this->uadata['os'] = 'Windows 95'; }
696 elseif ($this->uadata['os'] == 'Win98') { $this->uadata['os'] = 'Windows 98'; }
697 elseif ($this->uadata['os'] == 'WinNT') { $this->uadata['os'] = 'Windows NT'; }
698 elseif ($this->uadata['os'] == 'Win32') { $this->uadata['os'] = 'Windows (32bit)'; }
699 elseif ($this->uadata['os'] == 'Win64') { $this->uadata['os'] = 'Windows (64bit)'; }
700 elseif (preg_match('/Mac ?OS ?X/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; }
701 elseif (preg_match('/Mac_P(ower|)PC/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; }
702 elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
703 elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
704 elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
705 elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
706 elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
708 if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
709 elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
710 elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
711 elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
712 elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
713 elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
714 elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
715 elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
716 elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
717 elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
718 elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
719 elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
720 elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
721 elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
722 elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
723 elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
724 elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
725 else { $this->uadata['platform'] = $this->uadata['os']; }
727 $this->uadata['lang'] = str_replace('_', '-', $this->uadata['lang']);
729 return $this->uadata['os'];
732 function getPlatform() {
733 if (!isset($this->uadata['platform'])) {
734 $this->uadata['platform'] = null;
735 // getOS() should get the date for us
738 return $this->uadata['platform'];
741 function getLanguage() {
742 if (!isset($this->uadata['lang'])) {
743 $this->uadata['lang'] = null;
744 // getOS() should get the date for us
747 return $this->uadata['lang'];
750 function getGeckoDate() {
751 if (!isset($this->uadata['geckodate'])) {
752 $this->uadata['geckodate'] = null;
753 // getEngine() should get the date for us
756 return $this->uadata['geckodate'];
759 function isbot() { return $this->bot; }
760 function isns() { return (strpos($this->brand, 'Netscape') !== false); }
761 function isns4() { return ((strpos($this->brand, 'Netscape') !== false) && (intval($this->version) == 4)); }
762 function isie() { return $this->hasEngine('trident'); }
763 function geckodate() { return (!is_null($this->getGeckoDate())?$this->getGeckoDate():0); }
764 function geckobased() { return $this->hasEngine('gecko'); }
765 function khtmlbased() { return $this->hasEngine('khtml'); }