31733e08 |
1 | <?php |
a5813ca3 |
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 |
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 | |
31733e08 |
38 | class userAgent { |
39 | // userAgent PHP class |
40 | // get user agent and tell us what Browser is accessing |
41 | // |
1defa974 |
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. |
31733e08 |
44 | // |
45 | // var $uastring |
46 | // the plain User Agent string |
47 | // var $brand |
bf78d3ed |
48 | // the User Agent brand name |
31733e08 |
49 | // var $version |
50 | // the User Agent version |
a8464009 |
51 | // var $bot |
52 | // bool: true if this agent is a bot |
f983aa36 |
53 | // var $uadata |
54 | // array of static user agent data (static vars in functions are set for all objects of this class!) |
31733e08 |
55 | // |
23585ba2 |
56 | // function getBrand() |
57 | // returns the User Agent Brand Name |
bf78d3ed |
58 | // |
23585ba2 |
59 | // function getVersion() |
60 | // returns the User Agent version |
61 | // |
4210e7b0 |
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) |
65 | // |
f983aa36 |
66 | // function getUAString() |
67 | // returns the full User Agent string |
68 | // |
bf78d3ed |
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 |
72 | // |
73 | // function hasEngine($rnd_engine) |
74 | // returns true if the given rendering engine was detected |
75 | // |
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 |
79 | // |
80 | // function getOS() |
81 | // returns a string telling the detected operating system, null if we can't detect |
82 | // might be very verbose, uses no abbreviations for most names |
83 | // |
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 |
87 | // |
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 |
91 | // |
92 | // function isBot() |
a8464009 |
93 | // returns true if User Agent seems to be a bot |
bf78d3ed |
94 | // |
95 | // *** functions that only return useable info for some agents *** |
96 | // |
97 | // function getGeckoDate() |
98 | // returns the Gecko date for Gecko-based browsers, null for others |
99 | // |
100 | // *** functions for compat to older versions of this class *** |
101 | // |
31733e08 |
102 | // function isns() |
103 | // returns true if User Agent seems to be Netscape brand, false if not |
104 | // function isns4() |
105 | // returns true if User Agent seems to be Netscape Communicator 4.x, false if not |
106 | // function isie() |
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 |
1defa974 |
112 | // function khtmlbased() |
113 | // returns true if User Agent seems to be a KHTML-based browser, false if not |
114 | |
115 | // collection of some known User Agent Strings: |
bf78d3ed |
116 | // *** see testbed/ua_list_raw.txt *** |
117 | // *** see also http://www.pgts.com.au/pgtsj/pgtsj0208c.html *** |
31733e08 |
118 | |
31733e08 |
119 | var $uastring; |
120 | var $brand; |
121 | var $version; |
a8464009 |
122 | var $bot = false; |
f983aa36 |
123 | var $uadata = array(); |
31733e08 |
124 | |
4210e7b0 |
125 | function userAgent($ua_string = '') { |
31733e08 |
126 | // *** constructor *** |
1defa974 |
127 | if (strlen($ua_string)) { |
128 | $this->uastring = $ua_string; |
129 | } |
130 | else { |
131 | // read raw UA string |
4210e7b0 |
132 | $this->uastring = $_SERVER['HTTP_USER_AGENT']; |
1defa974 |
133 | } |
31733e08 |
134 | |
135 | // get UA brand and version |
bf78d3ed |
136 | $this->brand = 'Unknown'; $this->version = null; |
137 | // find reasonable defaults |
6e783db6 |
138 | if (preg_match('|([0-9a-zA-Z\.:()_ -]+)/([0-9a-zA-Z\._+-]+)|', $this->uastring, $regs)) { |
bf78d3ed |
139 | $this->brand = trim($regs[1]); |
140 | $this->version = $regs[2]; |
141 | } |
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]; |
145 | } |
146 | elseif (preg_match('|^([a-zA-Z\._ -]+)|', $this->uastring, $regs)) { |
147 | $this->brand = trim($regs[1]); |
148 | $this->version = null; |
149 | } |
81e72a3e |
150 | $this->bot = (strpos(strtolower($this->brand), 'bot') !== false) |
151 | || (strpos(strtolower($this->brand), 'crawler') !== false) |
152 | || (strpos(strtolower($this->brand), 'spider') !== false); |
153 | |
bf78d3ed |
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'; |
31733e08 |
157 | $this->version = $regs[1]; |
81e72a3e |
158 | $this->bot = false; |
31733e08 |
159 | } |
bf78d3ed |
160 | elseif (preg_match('|Netscape/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
161 | $this->brand = 'Netscape'; |
31733e08 |
162 | $this->version = $regs[1]; |
81e72a3e |
163 | $this->bot = false; |
31733e08 |
164 | } |
bf78d3ed |
165 | elseif (preg_match('|Chimera/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
166 | $this->brand = 'Chimera'; |
1defa974 |
167 | $this->version = $regs[1]; |
81e72a3e |
168 | $this->bot = false; |
1defa974 |
169 | } |
bf78d3ed |
170 | elseif (preg_match('|Camino/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
171 | $this->brand = 'Camino'; |
a5813ca3 |
172 | $this->version = $regs[1]; |
81e72a3e |
173 | $this->bot = false; |
a5813ca3 |
174 | } |
bf78d3ed |
175 | elseif (preg_match('|Phoenix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
176 | $this->brand = 'Phoenix'; |
1defa974 |
177 | $this->version = $regs[1]; |
81e72a3e |
178 | $this->bot = false; |
1defa974 |
179 | } |
bf78d3ed |
180 | elseif (preg_match('|Mozilla Firebird/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
181 | $this->brand = 'Mozilla Firebird'; |
23585ba2 |
182 | $this->version = $regs[1]; |
81e72a3e |
183 | $this->bot = false; |
23585ba2 |
184 | } |
bf78d3ed |
185 | elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
186 | $this->brand = 'Firefox'; |
a5813ca3 |
187 | $this->version = $regs[1]; |
81e72a3e |
188 | $this->bot = false; |
a5813ca3 |
189 | } |
b24eb888 |
190 | elseif (preg_match('|SeaMonkey/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
191 | $this->brand = 'SeaMonkey'; |
192 | $this->version = $regs[1]; |
81e72a3e |
193 | $this->bot = false; |
b24eb888 |
194 | } |
bf78d3ed |
195 | elseif (preg_match('|Galeon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
196 | $this->brand = 'Galeon'; |
31733e08 |
197 | $this->version = $regs[1]; |
81e72a3e |
198 | $this->bot = false; |
31733e08 |
199 | } |
6e783db6 |
200 | elseif (preg_match('|Epiphany/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
201 | $this->brand = 'Epiphany'; |
202 | $this->version = $regs[1]; |
81e72a3e |
203 | $this->bot = false; |
6e783db6 |
204 | } |
205 | elseif (preg_match('|K-Meleon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
206 | $this->brand = 'K-Meleon'; |
207 | $this->version = $regs[1]; |
81e72a3e |
208 | $this->bot = false; |
6e783db6 |
209 | } |
210 | elseif (preg_match('|AOL[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
211 | $this->brand = 'AOL'; |
212 | $this->version = $regs[1]; |
81e72a3e |
213 | $this->bot = false; |
6e783db6 |
214 | } |
bf78d3ed |
215 | elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) { |
216 | $this->brand = 'Mozilla'; |
31733e08 |
217 | $this->version = $regs[1]; |
81e72a3e |
218 | $this->bot = false; |
31733e08 |
219 | } |
bf78d3ed |
220 | elseif (preg_match('|Opera[ /]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
221 | $this->brand = 'Opera'; |
31733e08 |
222 | $this->version = $regs[1]; |
81e72a3e |
223 | $this->bot = false; |
31733e08 |
224 | } |
bf78d3ed |
225 | elseif (preg_match('|OmniWeb/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
226 | $this->brand = 'OmniWeb'; |
1defa974 |
227 | $this->version = $regs[1]; |
81e72a3e |
228 | $this->bot = false; |
1defa974 |
229 | } |
bf78d3ed |
230 | elseif (preg_match('|Konqueror/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
231 | $this->brand = 'Konqueror'; |
31733e08 |
232 | $this->version = $regs[1]; |
81e72a3e |
233 | $this->bot = false; |
31733e08 |
234 | } |
bf78d3ed |
235 | elseif (preg_match('|Safari/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
236 | $this->brand = 'Safari'; |
1defa974 |
237 | $this->version = $regs[1]; |
81e72a3e |
238 | $this->bot = false; |
1defa974 |
239 | } |
bf78d3ed |
240 | elseif (preg_match('|AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
241 | $this->brand = 'AppleWebKit'; |
1defa974 |
242 | $this->version = $regs[1]; |
81e72a3e |
243 | $this->bot = false; |
1defa974 |
244 | } |
bf78d3ed |
245 | elseif (preg_match('|MSFrontPage/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
246 | $this->brand = 'Microsoft FrontPage'; |
f983aa36 |
247 | $this->version = $regs[1]; |
81e72a3e |
248 | $this->bot = false; |
f983aa36 |
249 | } |
bf78d3ed |
250 | elseif (preg_match('|iCab[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
251 | $this->brand = 'iCab'; |
a8464009 |
252 | $this->version = $regs[1]; |
81e72a3e |
253 | $this->bot = false; |
a8464009 |
254 | } |
bf78d3ed |
255 | elseif (preg_match('|IBrowse[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
256 | $this->brand = 'IBrowse'; |
a8464009 |
257 | $this->version = $regs[1]; |
81e72a3e |
258 | $this->bot = false; |
a8464009 |
259 | } |
bf78d3ed |
260 | elseif (preg_match('|Configuration/CLDC-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
261 | $this->brand = 'CLDC'; |
a8464009 |
262 | $this->version = $regs[1]; |
81e72a3e |
263 | $this->bot = false; |
a8464009 |
264 | } |
6e783db6 |
265 | elseif (preg_match('|UP.Browser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
266 | $this->brand = 'UP.Browser'; |
267 | $this->version = $regs[1]; |
81e72a3e |
268 | $this->bot = false; |
6e783db6 |
269 | } |
bf78d3ed |
270 | elseif (preg_match('|ELinks \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) { |
271 | $this->brand = 'ELinks'; |
a8464009 |
272 | $this->version = $regs[1]; |
81e72a3e |
273 | $this->bot = false; |
a8464009 |
274 | } |
6e783db6 |
275 | elseif (preg_match('|Links \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) { |
276 | $this->brand = 'Links'; |
277 | $this->version = $regs[1]; |
81e72a3e |
278 | $this->bot = false; |
6e783db6 |
279 | } |
280 | elseif (preg_match('|wget[/ ]([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) { |
281 | $this->brand = 'wget'; |
282 | $this->version = $regs[1]; |
81e72a3e |
283 | $this->bot = false; |
6e783db6 |
284 | } |
bf78d3ed |
285 | elseif (preg_match('|ZyBorg/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
286 | $this->brand = 'ZyBorg'; |
a8464009 |
287 | $this->version = $regs[1]; |
288 | $this->bot = true; |
289 | } |
bf78d3ed |
290 | elseif (preg_match('|Googlebot/?([0-9a-zA-Z\.+]+)?|', $this->uastring, $regs)) { |
291 | $this->brand = 'Googlebot'; |
a8464009 |
292 | $this->version = $regs[1]; |
293 | $this->bot = true; |
294 | } |
bf78d3ed |
295 | elseif (preg_match('|Ask Jeeves/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
296 | $this->brand = 'Ask Jeeves'; |
a8464009 |
297 | $this->version = $regs[1]; |
298 | $this->bot = true; |
299 | } |
c51ab9a2 |
300 | elseif (preg_match('|Slurp|', $this->uastring, $regs)) { |
bf78d3ed |
301 | $this->brand = 'Slurp'; |
c51ab9a2 |
302 | $this->version = null; |
a8464009 |
303 | $this->bot = true; |
304 | } |
bf78d3ed |
305 | elseif (preg_match('|Gulper Web Bot ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
306 | $this->brand = 'Gulper Web Bot'; |
a8464009 |
307 | $this->version = $regs[1]; |
308 | $this->bot = true; |
309 | } |
bf78d3ed |
310 | elseif (preg_match('|HTTrack ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
311 | $this->brand = 'HTTrack'; |
a8464009 |
312 | $this->version = $regs[1]; |
313 | $this->bot = true; |
314 | } |
81e72a3e |
315 | elseif (preg_match('|([0-9a-zA-Z\.+]+)_AC-Plug|', $this->uastring, $regs)) { |
316 | $this->brand = 'AC-Plug'; |
317 | $this->version = $regs[1]; |
318 | $this->bot = true; |
319 | } |
bf78d3ed |
320 | elseif (preg_match('|^Internet Explorer 5.5|', $this->uastring)) { |
321 | $this->brand = 'Unknown bot (IE5.5)'; |
322 | $this->version = null; |
a8464009 |
323 | $this->bot = true; |
324 | } |
bf78d3ed |
325 | elseif (preg_match('|^Mozilla[\s ]*$|', $this->uastring)) { |
326 | $this->brand = 'Unknown bot (Mozilla)'; |
327 | $this->version = null; |
a8464009 |
328 | $this->bot = true; |
329 | } |
bf78d3ed |
330 | elseif (preg_match('|http://www.almaden.ibm.com/cs/crawler|', $this->uastring)) { |
331 | $this->brand = 'almaden crawler'; |
332 | $this->version = null; |
a8464009 |
333 | $this->bot = true; |
334 | } |
bf78d3ed |
335 | 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)) { |
336 | $this->brand = 'BlitzBOT'; |
337 | $this->version = null; |
a8464009 |
338 | $this->bot = true; |
339 | } |
bf78d3ed |
340 | elseif (preg_match('|sitecheck.internetseer.com|', $this->uastring)) { |
341 | $this->brand = 'internetseer'; |
342 | $this->version = null; |
a8464009 |
343 | $this->bot = true; |
344 | } |
bf78d3ed |
345 | elseif (preg_match('|Girafabot|', $this->uastring)) { |
346 | $this->brand = 'Girafabot'; |
347 | $this->version = null; |
a8464009 |
348 | $this->bot = true; |
349 | } |
bf78d3ed |
350 | elseif (preg_match('|efp@gmx.net|', $this->uastring)) { |
351 | $this->brand = 'efp'; |
352 | $this->version = null; |
a8464009 |
353 | $this->bot = true; |
354 | } |
81e72a3e |
355 | elseif (preg_match('|42_HAL|', $this->uastring)) { |
356 | $this->brand = '42_HAL'; |
357 | $this->version = null; |
358 | $this->bot = true; |
359 | } |
360 | elseif (preg_match('|Baiduspider|i', $this->uastring)) { |
361 | $this->brand = 'BaiDuSpider'; |
362 | $this->version = null; |
363 | $this->bot = true; |
364 | } |
365 | elseif (preg_match('|Indy Library|', $this->uastring)) { |
366 | $this->brand = 'Indy Library'; |
367 | $this->version = null; |
368 | $this->bot = true; |
369 | } |
bf78d3ed |
370 | elseif (preg_match('|^Firefly|', $this->uastring)) { |
371 | // comes here with correct value but would be detected as MSIE |
a8464009 |
372 | } |
81e72a3e |
373 | elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) { |
374 | $this->brand = 'Steganos Internet Anonym'; |
375 | $this->version = $regs[1]; |
376 | $this->bot = false; |
377 | } |
bf78d3ed |
378 | elseif (preg_match('|Avant Browser[^/]|', $this->uastring)) { |
379 | $this->brand = 'Avant Browser'; |
380 | $this->version = null; |
81e72a3e |
381 | $this->bot = false; |
a8464009 |
382 | } |
6e783db6 |
383 | elseif (preg_match('|Maxthon|', $this->uastring)) { |
384 | $this->brand = 'Maxthon'; |
385 | $this->version = null; |
81e72a3e |
386 | $this->bot = false; |
6e783db6 |
387 | } |
388 | elseif (preg_match('|MyIE2|', $this->uastring)) { |
389 | $this->brand = 'MyIE2'; |
390 | $this->version = null; |
81e72a3e |
391 | $this->bot = false; |
6e783db6 |
392 | } |
bf78d3ed |
393 | elseif (preg_match('|Crazy Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
394 | $this->brand = 'Crazy Browser'; |
395 | $this->version = $regs[1]; |
81e72a3e |
396 | $this->bot = false; |
397 | } |
398 | elseif (preg_match('|AvantGo ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
399 | $this->brand = 'AvantGo'; |
400 | $this->version = $regs[1]; |
401 | $this->bot = false; |
a8464009 |
402 | } |
bf78d3ed |
403 | elseif (preg_match('|MSN ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
404 | $this->brand = 'MSN'; |
405 | $this->version = $regs[1]; |
81e72a3e |
406 | $this->bot = false; |
a8464009 |
407 | } |
bf78d3ed |
408 | elseif (preg_match('|MS FrontPage ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
409 | $this->brand = 'Microsoft FrontPage'; |
410 | $this->version = $regs[1]; |
81e72a3e |
411 | $this->bot = false; |
a8464009 |
412 | } |
bf78d3ed |
413 | elseif (preg_match('|MSIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
414 | $this->brand = 'Microsoft Internet Explorer'; |
31733e08 |
415 | $this->version = $regs[1]; |
81e72a3e |
416 | $this->bot = false; |
31733e08 |
417 | } |
81e72a3e |
418 | elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) && (strpos($this->uastring, 'compatible;') === false) && (strpos($this->uastring, 'Gecko/') === false)) { |
bf78d3ed |
419 | $this->brand = 'Netscape'; |
1defa974 |
420 | $this->version = $regs[1]; |
bf78d3ed |
421 | if (intval($this->version) == 4) { $this->brand .= ' Communicator'; } |
81e72a3e |
422 | $this->bot = false; |
423 | } |
424 | elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) && (strpos($this->uastring, 'compatible;') !== false)) { |
425 | $this->brand = 'Mozilla-compatible (unknown)'; |
426 | $this->version = null; |
427 | $this->bot = false; |
1defa974 |
428 | } |
a8464009 |
429 | |
81e72a3e |
430 | $botArray = array('Scooter','Spinne','Vagabondo','Firefly','Scrubby','NG','Pompos','Szukacz','ASPseek', |
431 | 'NetResearchServer','LinkWalker','Zeus','W3C_Validator','ZyBorg','Ask Jeeves','ia_archiver', |
432 | 'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','search.ch', |
433 | 'appie','larbin','NutchCVS','ObjectsSearch','Webchat','Mediapartners-Google','Schmozilla', |
434 | 'FavOrg','findlinks','DataCha0s','','','','','','','','',''); |
a8464009 |
435 | |
436 | if (in_array($this->brand, $botArray)) { |
437 | $this->bot = true; |
438 | } |
31733e08 |
439 | } |
440 | |
23585ba2 |
441 | function getBrand() { return $this->brand; } |
442 | function getVersion() { return $this->version; } |
4210e7b0 |
443 | |
444 | function getAcceptLanguages() { |
445 | if (!isset($this->uadata['accept-languages'])) { |
446 | $headers = getAllHeaders(); |
447 | $accLcomp = explode(',', $headers['Accept-Language']); |
448 | $accLang = array(); |
449 | foreach ($accLcomp as $lcomp) { |
450 | if (strlen($lcomp)) { |
451 | $ldef = explode(';', $lcomp); |
452 | $accLang[$ldef[0]] = (float)((strpos($ldef[1],'q=')===0)?substr($ldef[1],2):1); |
453 | } |
454 | } |
455 | $this->uadata['accept-languages'] = $accLang; |
456 | } |
457 | return $this->uadata['accept-languages']; |
458 | } |
459 | |
f983aa36 |
460 | function getUAString() { return $this->uastring; } |
23585ba2 |
461 | |
bf78d3ed |
462 | function getEngine() { |
463 | // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|unkown |
464 | if (!isset($this->uadata['engine'])) { |
465 | $this->uadata['engine'] = 'unkown'; |
466 | $this->uadata['geckodate'] = null; |
467 | if (preg_match('|Gecko/([0-9]+)|', $this->uastring, $regs)) { |
468 | $this->uadata['engine'] = 'gecko'; |
469 | $this->uadata['geckodate'] = $regs[1]; |
470 | } |
471 | elseif ((strpos($this->brand, 'Internet Explorer') !== false) || (strpos($this->brand, 'FrontPage') !== false)) { |
6e783db6 |
472 | if ((strpos(strtolower($this->uastring), 'mac') !== false) && (intval($this->getVersion()) >= 5)) { |
bf78d3ed |
473 | $this->uadata['engine'] = 'tasman'; |
474 | } |
475 | else { |
476 | $this->uadata['engine'] = 'trident'; |
477 | } |
478 | } |
479 | elseif ((strpos($this->brand, 'Konqueror') !== false) || (strpos($this->brand, 'Safari') !== false) || (strpos($this->brand, 'AppleWebKit') !== false) || (strpos($this->brand, 'OmniWeb') !== false)) { |
480 | $this->uadata['engine'] = 'khtml'; |
481 | } |
81e72a3e |
482 | elseif (strpos($this->brand, 'Netscape') !== false) { |
483 | // non-Gecko Netscape browsers |
484 | if (intval($this->version) <= 4) { |
485 | $this->uadata['engine'] = 'nscp'; |
486 | } |
487 | elseif (strpos($this->uastring, 'MSIE') !== false) { |
488 | $this->uadata['engine'] = 'trident'; |
489 | } |
bf78d3ed |
490 | } |
491 | elseif (strpos($this->brand, 'Opera') !== false) { |
492 | $this->uadata['engine'] = 'presto'; |
493 | } |
494 | elseif (strpos($this->brand, 'Dillo') !== false) { |
495 | $this->uadata['engine'] = 'gzilla'; |
496 | } |
497 | elseif ((strpos($this->brand, 'ELinks') !== false) || (strpos($this->brand, 'Links') !== false)) { |
498 | $this->uadata['engine'] = 'links'; |
499 | } |
6e783db6 |
500 | elseif ((strpos($this->brand, 'Avant') !== false) || (strpos($this->brand, 'Crazy Browser') !== false) || |
501 | (strpos($this->brand, 'AOL') !== false) || (strpos($this->brand, 'MSN') !== false) || |
502 | (strpos($this->brand, 'MyIE2') !== false) || (strpos($this->brand, 'Maxthon') !== false)) { |
bf78d3ed |
503 | $this->uadata['engine'] = 'trident'; |
504 | } |
505 | elseif (strpos($this->brand, 'Galeon') !== false) { |
506 | $this->uadata['engine'] = 'gecko'; |
31733e08 |
507 | } |
508 | } |
bf78d3ed |
509 | return $this->uadata['engine']; |
31733e08 |
510 | } |
511 | |
bf78d3ed |
512 | function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); } |
513 | |
514 | function getEngineVersion() { |
515 | if (!isset($this->uadata['eng_version'])) { |
516 | $this->uadata['eng_version'] = null; |
517 | // getOS() should get the date for us |
518 | $this->getOS(); |
31733e08 |
519 | } |
bf78d3ed |
520 | return $this->uadata['eng_version']; |
31733e08 |
521 | } |
522 | |
bf78d3ed |
523 | function getOS() { |
524 | if (!isset($this->uadata['os'])) { |
525 | $this->uadata['os'] = null; |
526 | if ($this->hasEngine('gecko')) { |
81e72a3e |
527 | if (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) { |
bf78d3ed |
528 | $this->uadata['os'] = $regs[2]; |
529 | $this->uadata['lang'] = $regs[3]; |
530 | $this->uadata['eng_version'] = $regs[4]; |
531 | } |
81e72a3e |
532 | elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) { |
533 | $this->uadata['os'] = $regs[2]; |
534 | $this->uadata['lang'] = null; |
535 | $this->uadata['eng_version'] = $regs[3]; |
536 | } |
6e783db6 |
537 | elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) { |
bf78d3ed |
538 | $this->uadata['os'] = $regs[2]; |
539 | $this->uadata['lang'] = $regs[3]; |
540 | $this->uadata['eng_version'] = 'M'.$regs[4]; |
541 | } |
6e783db6 |
542 | elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) { |
543 | $this->uadata['os'] = $regs[2]; |
544 | $this->uadata['lang'] = $regs[3]; |
545 | $this->uadata['eng_version'] = null; |
546 | } |
547 | elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^\);]+)\)|', $this->uastring, $regs)) { |
bf78d3ed |
548 | $this->uadata['os'] = $regs[2]; |
549 | $this->uadata['lang'] = null; |
550 | $this->uadata['eng_version'] = null; |
551 | } |
552 | elseif (preg_match('|Mozilla/5.0 Galeon/[^\(]+ \(([^;]+); ([^;]+);[^\)]+\)|', $this->uastring, $regs)) { |
553 | $this->uadata['os'] = $regs[2]; |
554 | $this->uadata['lang'] = null; |
555 | $this->uadata['eng_version'] = null; |
556 | } |
557 | elseif (preg_match('|Debian/|', $this->uastring, $regs)) { |
558 | $this->uadata['os'] = 'Debian Linux'; |
559 | $this->uadata['lang'] = null; |
560 | $this->uadata['eng_version'] = null; |
561 | } |
562 | } |
6e783db6 |
563 | elseif ($this->hasEngine('trident') || $this->hasEngine('tasman')) { |
81e72a3e |
564 | if (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+)[^\)]*\)/i', $this->uastring, $regs)) { |
bf78d3ed |
565 | $this->uadata['eng_version'] = $regs[1]; |
566 | $this->uadata['os'] = $regs[2]; |
567 | $this->uadata['lang'] = null; |
568 | } |
81e72a3e |
569 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE ([^;]+)[^\)]*\)/i', $this->uastring, $regs)) { |
bf78d3ed |
570 | $this->uadata['eng_version'] = $regs[1]; |
571 | $this->uadata['os'] = null; |
572 | $this->uadata['lang'] = null; |
573 | } |
31733e08 |
574 | } |
bf78d3ed |
575 | elseif ($this->hasEngine('khtml')) { |
6e783db6 |
576 | if (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^;]+); ([^;]+); ([^;]+); ([^\);]+)\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) { |
577 | $this->uadata['eng_version'] = strlen($regs[6])?$regs[6]:$regs[1]; |
bf78d3ed |
578 | $this->uadata['os'] = $regs[2]; |
579 | $this->uadata['lang'] = $regs[5]; |
580 | } |
6e783db6 |
581 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^\);]+)[^\)]*\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) { |
582 | $this->uadata['eng_version'] = strlen($regs[3])?$regs[3]:$regs[1]; |
bf78d3ed |
583 | $this->uadata['os'] = $regs[2]; |
584 | $this->uadata['lang'] = null; |
585 | } |
586 | elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) { |
587 | $this->uadata['os'] = $regs[2]; |
588 | $this->uadata['lang'] = $regs[3]; |
589 | $this->uadata['eng_version'] = null; |
590 | } |
591 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; [^;]+; ([^\);]+)\)/i', $this->uastring, $regs)) { |
592 | $this->uadata['os'] = $regs[1]; |
593 | $this->uadata['lang'] = null; |
594 | $this->uadata['eng_version'] = null; |
595 | } |
596 | } |
597 | elseif ($this->hasEngine('presto')) { |
598 | if (preg_match('/Opera\/[^\(]+ \(([^;]+)[^\)]+\) +\[([a-z_-]+)\]/i', $this->uastring, $regs)) { |
599 | $this->uadata['eng_version'] = $this->getVersion(); |
600 | $this->uadata['os'] = $regs[1]; |
601 | $this->uadata['lang'] = $regs[2]; |
602 | } |
6e783db6 |
603 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; .+; ([^;]+)\) Opera [^ ]+ \[([a-z_-]+)\]/i', $this->uastring, $regs)) { |
604 | $this->uadata['eng_version'] = $this->getVersion(); |
605 | $this->uadata['os'] = $regs[1]; |
606 | $this->uadata['lang'] = $regs[2]; |
607 | } |
608 | elseif (preg_match('/Mozilla\/[^\(]+ \(([^;]+);.+\) Opera [^ ]+ \[([a-z_-]+)\]/i', $this->uastring, $regs)) { |
609 | $this->uadata['eng_version'] = $this->getVersion(); |
610 | $this->uadata['os'] = $regs[1]; |
611 | $this->uadata['lang'] = $regs[2]; |
612 | } |
613 | // Opera 8 |
bf78d3ed |
614 | elseif (preg_match('/Opera\/[^\(]+ \(([^;]+); [^\)]+; ([a-z_-]+)\)/i', $this->uastring, $regs)) { |
615 | $this->uadata['eng_version'] = $this->getVersion(); |
616 | $this->uadata['os'] = $regs[1]; |
617 | $this->uadata['lang'] = $regs[2]; |
618 | } |
6e783db6 |
619 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; .+; ([^;]+); ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) { |
620 | $this->uadata['eng_version'] = $this->getVersion(); |
621 | $this->uadata['os'] = $regs[1]; |
622 | $this->uadata['lang'] = $regs[2]; |
623 | } |
624 | elseif (preg_match('/Mozilla\/[^\(]+ \(([^;]+);.+; ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) { |
bf78d3ed |
625 | $this->uadata['eng_version'] = $this->getVersion(); |
626 | $this->uadata['os'] = $regs[1]; |
627 | $this->uadata['lang'] = $regs[2]; |
628 | } |
629 | } |
630 | elseif ($this->hasEngine('nscp')) { |
6e783db6 |
631 | if (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) { |
bf78d3ed |
632 | $this->uadata['eng_version'] = $regs[1]; |
633 | $this->uadata['os'] = $regs[3]; |
634 | $this->uadata['lang'] = $regs[2]; |
635 | } |
636 | } |
637 | elseif ($this->hasEngine('gzilla')) { |
638 | $this->uadata['eng_version'] = $this->getVersion(); |
639 | $this->uadata['os'] = null; |
640 | $this->uadata['lang'] = null; |
641 | } |
642 | elseif ($this->hasEngine('links')) { |
6e783db6 |
643 | if (preg_match('/E?Links[^\(]+\([^;]+; ([^;]+)[^\)]+\)/i', $this->uastring, $regs)) { |
bf78d3ed |
644 | $this->uadata['eng_version'] = null; |
645 | $this->uadata['os'] = $regs[1]; |
646 | $this->uadata['lang'] = null; |
647 | } |
648 | } |
649 | else { |
650 | $this->uadata['eng_version'] = null; |
651 | $this->uadata['lang'] = null; |
652 | if (preg_match('/AmigaOS/i', $this->uastring, $regs)) { |
653 | $this->uadata['os'] = 'AmigaOS'; |
654 | } |
655 | elseif (preg_match('/curl\/[^\(]+\(([^\);]+)/i', $this->uastring, $regs)) { |
656 | $this->uadata['os'] = $regs[1]; |
657 | } |
6e783db6 |
658 | elseif (preg_match('/NCSA[_ ]Mosaic\/[^\(]+\((?:.*;)?([^\);]+)/i', $this->uastring, $regs)) { |
659 | $this->uadata['os'] = trim($regs[1]); |
660 | } |
661 | elseif (preg_match('/iCab.*(Mac[^\);]+).*?\)/i', $this->uastring, $regs)) { |
662 | $this->uadata['os'] = trim($regs[1]); |
663 | } |
c51ab9a2 |
664 | elseif (preg_match('/SymbianOS\/([^ ]+)/i', $this->uastring, $regs)) { |
665 | $this->uadata['os'] = 'SymbianOS '.$regs[1]; |
666 | } |
bf78d3ed |
667 | } |
668 | if ($this->uadata['os'] == 'Win 9x 4.90') { $this->uadata['os'] = 'Windows ME'; } |
669 | elseif ($this->uadata['os'] == 'WinNT4.0') { $this->uadata['os'] = 'Windows ME'; } |
670 | elseif ($this->uadata['os'] == 'Windows NT 5.0') { $this->uadata['os'] = 'Windows 2000'; } |
671 | elseif ($this->uadata['os'] == 'Windows NT 5.1') { $this->uadata['os'] = 'Windows XP'; } |
672 | elseif ($this->uadata['os'] == 'Windows NT 5.2') { $this->uadata['os'] = 'Windows 2003'; } |
673 | elseif ($this->uadata['os'] == 'Win95') { $this->uadata['os'] = 'Windows 95'; } |
674 | elseif ($this->uadata['os'] == 'Win98') { $this->uadata['os'] = 'Windows 98'; } |
675 | elseif (preg_match('/Mac ?OS ?X/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; } |
676 | elseif (preg_match('/Mac_P(ower|)PC/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; } |
677 | elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; } |
6e783db6 |
678 | elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; } |
bf78d3ed |
679 | elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; } |
6e783db6 |
680 | elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; } |
bf78d3ed |
681 | elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; } |
682 | |
6e783db6 |
683 | if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; } |
684 | elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; } |
685 | elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; } |
686 | elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; } |
687 | elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; } |
688 | elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; } |
689 | elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; } |
690 | elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; } |
691 | elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; } |
692 | elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; } |
693 | elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; } |
694 | elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; } |
695 | elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; } |
696 | elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; } |
697 | elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; } |
c51ab9a2 |
698 | elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; } |
6e783db6 |
699 | elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; } |
700 | else { $this->uadata['platform'] = $this->uadata['os']; } |
bf78d3ed |
701 | |
702 | $this->uadata['lang'] = str_replace('_', '-', $this->uadata['lang']); |
31733e08 |
703 | } |
bf78d3ed |
704 | return $this->uadata['os']; |
31733e08 |
705 | } |
706 | |
bf78d3ed |
707 | function getPlatform() { |
708 | if (!isset($this->uadata['platform'])) { |
709 | $this->uadata['platform'] = null; |
710 | // getOS() should get the date for us |
711 | $this->getOS(); |
31733e08 |
712 | } |
bf78d3ed |
713 | return $this->uadata['platform']; |
31733e08 |
714 | } |
715 | |
bf78d3ed |
716 | function getLanguage() { |
717 | if (!isset($this->uadata['lang'])) { |
718 | $this->uadata['lang'] = null; |
719 | // getOS() should get the date for us |
720 | $this->getOS(); |
31733e08 |
721 | } |
bf78d3ed |
722 | return $this->uadata['lang']; |
31733e08 |
723 | } |
1defa974 |
724 | |
bf78d3ed |
725 | function getGeckoDate() { |
726 | if (!isset($this->uadata['geckodate'])) { |
727 | $this->uadata['geckodate'] = null; |
728 | // getEngine() should get the date for us |
729 | $this->getEngine(); |
1defa974 |
730 | } |
bf78d3ed |
731 | return $this->uadata['geckodate']; |
1defa974 |
732 | } |
bf78d3ed |
733 | |
734 | function isbot() { return $this->bot; } |
735 | function isns() { return (strpos($this->brand, 'Netscape') !== false); } |
736 | function isns4() { return ((strpos($this->brand, 'Netscape') !== false) && (intval($this->version) == 4)); } |
737 | function isie() { return $this->hasEngine('trident'); } |
738 | function geckodate() { return (!is_null($this->getGeckoDate())?$this->getGeckoDate():0); } |
739 | function geckobased() { return $this->hasEngine('gecko'); } |
740 | function khtmlbased() { return $this->hasEngine('khtml'); } |
31733e08 |
741 | } |
23585ba2 |
742 | ?> |