1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare API - Client browser detection * |
---|
4 | * ------------------------------------------------------------------------ * |
---|
5 | * This is not part of eGroupWare, but is used by eGroupWare. * |
---|
6 | * http://www.egroupware.org/ * |
---|
7 | * ------------------------------------------------------------------------ * |
---|
8 | * This program is free software; you can redistribute it and/or modify it * |
---|
9 | * under the terms of the GNU General Public License as published by the * |
---|
10 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
11 | * option) any later version. * |
---|
12 | \**************************************************************************/ |
---|
13 | |
---|
14 | /****************************************** |
---|
15 | ** Description : PHPClientSniffer |
---|
16 | ** Version : 1.0.0 |
---|
17 | ** File Name : PHPClientSniffer.php3 |
---|
18 | ** Author : Roger Raymond for PHyX8 studios |
---|
19 | ** Author Email : roger.raymond@asphyxia.com |
---|
20 | ** Created : Wednesday, August 23, 2000 |
---|
21 | ** Last Modified : |
---|
22 | ** Modified By : |
---|
23 | *' |
---|
24 | INFO: |
---|
25 | Returns client information based on HTTP_USER_AGENT |
---|
26 | |
---|
27 | BASED ON WORKS AND IDEAS BY: |
---|
28 | Tim Perdue of PHPBuilder.com |
---|
29 | http://www.phpbuilder.com/columns/tim20000821.php3 |
---|
30 | |
---|
31 | The Ultimate JavaScript Client Sniffer by Netscape. |
---|
32 | http://developer.netscape.com/docs/examples/javascript/NAME_type.html |
---|
33 | |
---|
34 | ======================================================================== |
---|
35 | USAGE: |
---|
36 | ======================================================================== |
---|
37 | include("PHPClientSniffer.php3"); |
---|
38 | $is = new sniffer; |
---|
39 | ======================================================================== |
---|
40 | VARIABLE NAMES VALUES |
---|
41 | ======================================================================== |
---|
42 | $is->UA The HTTP USER AGENT String |
---|
43 | $is->NAME Browser Name (Netscape, IE, Opera, iCab, Unknown) |
---|
44 | $is->VERSION Browser Full Version |
---|
45 | $is->MAJORVER Browser Major Version |
---|
46 | $is->MINORVER Browser Minor Version |
---|
47 | $is->AOL True/False |
---|
48 | $is->WEBTV True/False |
---|
49 | $is->JS Assumed JavaScript Version Supported by Browser |
---|
50 | $is->PLATFORM System Platform (Win16,Win32,Mac,OS2,Unix) |
---|
51 | $is->OS System OS (Win98,OS2,Mac68k,linux,bsd,etc...) see code |
---|
52 | $is->IP REMOTE_ADDR |
---|
53 | |
---|
54 | ======================================================================== |
---|
55 | |
---|
56 | '****************************************/ |
---|
57 | |
---|
58 | class clientsniffer |
---|
59 | { |
---|
60 | var $UA = ''; |
---|
61 | var $NAME = 'Unknown'; |
---|
62 | var $VERSION = 0; |
---|
63 | var $MAJORVER = 0; |
---|
64 | var $MINORVER = 0; |
---|
65 | var $AOL = false; |
---|
66 | var $WEBTV = false; |
---|
67 | var $JS = 0.0; |
---|
68 | var $PLATFORM = 'Unknown'; |
---|
69 | var $OS = 'Unknown'; |
---|
70 | var $IP = 'Unknown'; |
---|
71 | |
---|
72 | /* START CONSTRUCTOR */ |
---|
73 | function clientsniffer() |
---|
74 | { |
---|
75 | $this->UA = getenv(HTTP_USER_AGENT); |
---|
76 | |
---|
77 | // Determine NAME Name and Version |
---|
78 | if ( eregi( 'MSIE ([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) || |
---|
79 | eregi( 'Microsoft Internet Explorer ([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) ) |
---|
80 | { |
---|
81 | $this->VERSION = $info[1]; |
---|
82 | $this->NAME = 'IE'; |
---|
83 | } |
---|
84 | elseif ( eregi( 'Opera ([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) || |
---|
85 | eregi( 'Opera/([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) ) |
---|
86 | { |
---|
87 | $this->VERSION = $info[1]; |
---|
88 | $this->NAME = 'Opera'; |
---|
89 | } |
---|
90 | elseif ( eregi( 'iCab ([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) || |
---|
91 | eregi( 'iCab/([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) ) |
---|
92 | { |
---|
93 | $this->VERSION = $info[1]; |
---|
94 | $this->NAME = 'iCab'; |
---|
95 | } |
---|
96 | elseif ( eregi( 'Netscape6/([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) ) |
---|
97 | { |
---|
98 | $this->VERSION = $info[1]; |
---|
99 | $this->NAME = 'Netscape'; |
---|
100 | } |
---|
101 | elseif ( eregi( 'Mozilla/([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) ) |
---|
102 | { |
---|
103 | $this->VERSION = $info[1]; |
---|
104 | $this->NAME = 'Netscape'; |
---|
105 | } |
---|
106 | else |
---|
107 | { |
---|
108 | $this->VERSION = 0; |
---|
109 | $this->NAME = 'Unknown'; |
---|
110 | } |
---|
111 | |
---|
112 | // Determine if AOL or WEBTV |
---|
113 | if( eregi( 'aol',$this->UA,$info)) |
---|
114 | { |
---|
115 | $this->AOL = true; |
---|
116 | } |
---|
117 | elseif( eregi( 'webtv',$this->UA,$info)) |
---|
118 | { |
---|
119 | $this->WEBTV = true; |
---|
120 | } |
---|
121 | |
---|
122 | // Determine Major and Minor Version |
---|
123 | if($this->VERSION > 0) |
---|
124 | { |
---|
125 | $pos = strpos($this->VERSION,'.'); |
---|
126 | if ($pos > 0) |
---|
127 | { |
---|
128 | $this->MAJORVER = substr($this->VERSION,0,$pos); |
---|
129 | $this->MINORVER = substr($this->VERSION,$pos,strlen($this->VERSION)); |
---|
130 | } |
---|
131 | else |
---|
132 | { |
---|
133 | $this->MAJORVER = $this->VERSION; |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | // Determine Platform and OS |
---|
138 | |
---|
139 | // Check for Windows 16-bit |
---|
140 | if( eregi('Win16',$this->UA) || |
---|
141 | eregi('windows 3.1',$this->UA) || |
---|
142 | eregi('windows 16-bit',$this->UA) || |
---|
143 | eregi('16bit',$this->UA)) |
---|
144 | { |
---|
145 | $this->PLATFORM = 'Win16'; |
---|
146 | $this->OS = 'Win31'; |
---|
147 | } |
---|
148 | |
---|
149 | // Check for Windows 32-bit |
---|
150 | if(eregi('Win95',$this->UA) || eregi('windows 95',$this->UA)) |
---|
151 | { |
---|
152 | $this->PLATFORM = 'Win32'; |
---|
153 | $this->OS = 'Win95'; |
---|
154 | } |
---|
155 | elseif(eregi('Win98',$this->UA) || eregi('windows 98',$this->UA)) |
---|
156 | { |
---|
157 | $this->PLATFORM = 'Win32'; |
---|
158 | $this->OS = 'Win98'; |
---|
159 | } |
---|
160 | elseif(eregi('WinNT',$this->UA) || eregi('windows NT',$this->UA)) |
---|
161 | { |
---|
162 | $this->PLATFORM = 'Win32'; |
---|
163 | $this->OS = 'WinNT'; |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | $this->PLATFORM = 'Win32'; |
---|
168 | $this->OS = 'Win9xNT'; |
---|
169 | } |
---|
170 | |
---|
171 | // Check for OS/2 |
---|
172 | if( eregi('os/2',$this->UA) || eregi('ibm-webexplorer',$this->UA)) |
---|
173 | { |
---|
174 | $this->PLATFORM = 'OS2'; |
---|
175 | $this->OS = 'OS2'; |
---|
176 | } |
---|
177 | |
---|
178 | // Check for Mac 68000 |
---|
179 | if( eregi('68k',$this->UA) || eregi('68000',$this->UA)) |
---|
180 | { |
---|
181 | $this->PLATFORM = 'Mac'; |
---|
182 | $this->OS = 'Mac68k'; |
---|
183 | } |
---|
184 | |
---|
185 | //Check for Mac PowerPC |
---|
186 | if( eregi('ppc',$this->UA) || eregi('powerpc',$this->UA)) |
---|
187 | { |
---|
188 | $this->PLATFORM = 'Mac'; |
---|
189 | $this->OS = 'MacPPC'; |
---|
190 | } |
---|
191 | |
---|
192 | // Check for Unix Flavor |
---|
193 | |
---|
194 | //SunOS |
---|
195 | if(eregi('sunos',$this->UA)) |
---|
196 | { |
---|
197 | $this->PLATFORM = 'Unix'; |
---|
198 | $this->OS = 'sun'; |
---|
199 | } |
---|
200 | if(eregi('sunos 4',$this->UA)) |
---|
201 | { |
---|
202 | $this->PLATFORM = 'Unix'; |
---|
203 | $this->OS = 'sun4'; |
---|
204 | } |
---|
205 | elseif(eregi('sunos 5',$this->UA)) |
---|
206 | { |
---|
207 | $this->PLATFORM = 'Unix'; |
---|
208 | $this->OS = 'sun5'; |
---|
209 | } |
---|
210 | elseif(eregi('i86',$this->UA)) |
---|
211 | { |
---|
212 | $this->PLATFORM = 'Unix'; |
---|
213 | $this->OS = 'suni86'; |
---|
214 | } |
---|
215 | |
---|
216 | // Irix |
---|
217 | if(eregi('irix',$this->UA)) |
---|
218 | { |
---|
219 | $this->PLATFORM = 'Unix'; |
---|
220 | $this->OS = 'irix'; |
---|
221 | } |
---|
222 | if(eregi('irix 6',$this->UA)) |
---|
223 | { |
---|
224 | $this->PLATFORM = 'Unix'; |
---|
225 | $this->OS = 'irix6'; |
---|
226 | } |
---|
227 | elseif(eregi('irix 5',$this->UA)) |
---|
228 | { |
---|
229 | $this->PLATFORM = 'Unix'; |
---|
230 | $this->OS = 'irix5'; |
---|
231 | } |
---|
232 | |
---|
233 | //HP-UX |
---|
234 | if(eregi('hp-ux',$this->UA)) |
---|
235 | { |
---|
236 | $this->PLATFORM = 'Unix'; |
---|
237 | $this->OS = 'hpux'; |
---|
238 | } |
---|
239 | if(eregi('hp-ux',$this->UA) && ereg('10.',$this-UA)) |
---|
240 | { |
---|
241 | $this->PLATFORM = 'Unix'; |
---|
242 | $this->OS = 'hpux10'; |
---|
243 | } |
---|
244 | elseif(eregi('hp-ux',$this->UA) && ereg('09.',$this-UA)) |
---|
245 | { |
---|
246 | $this->PLATFORM = 'Unix'; |
---|
247 | $this->OS = 'hpux9'; |
---|
248 | } |
---|
249 | |
---|
250 | //AIX |
---|
251 | if(eregi('aix',$this->UA)) |
---|
252 | { |
---|
253 | $this->PLATFORM = 'Unix'; |
---|
254 | $this->OS = 'aix'; |
---|
255 | } |
---|
256 | if(eregi('aix1',$this->UA)) |
---|
257 | { |
---|
258 | $this->PLATFORM = 'Unix'; |
---|
259 | $this->OS = 'aix1'; |
---|
260 | } |
---|
261 | elseif(eregi('aix2',$this->UA)) |
---|
262 | { |
---|
263 | $this->PLATFORM = 'Unix'; |
---|
264 | $this->OS = 'aix2'; |
---|
265 | } |
---|
266 | elseif(eregi('aix3',$this->UA)) |
---|
267 | { |
---|
268 | $this->PLATFORM = 'Unix'; |
---|
269 | $this->OS = 'aix3'; |
---|
270 | } |
---|
271 | elseif(eregi('aix4',$this->UA)) |
---|
272 | { |
---|
273 | $this->PLATFORM = 'Unix'; |
---|
274 | $this->OS = 'aix4'; |
---|
275 | } |
---|
276 | |
---|
277 | // Linux |
---|
278 | if(eregi('inux',$this->UA)) |
---|
279 | { |
---|
280 | $this->PLATFORM = 'Unix'; |
---|
281 | $this->OS = 'linux'; |
---|
282 | } |
---|
283 | |
---|
284 | //Unixware |
---|
285 | if(eregi('unix_system_v',$this->UA)) |
---|
286 | { |
---|
287 | $this->PLATFORM = 'Unix'; |
---|
288 | $this->OS = 'unixware'; |
---|
289 | } |
---|
290 | |
---|
291 | //mpras |
---|
292 | if(eregi('ncr',$this->UA)) |
---|
293 | { |
---|
294 | $this->PLATFORM = 'Unix'; |
---|
295 | $this->OS = 'mpras'; |
---|
296 | } |
---|
297 | |
---|
298 | //Reliant |
---|
299 | if(eregi('reliantunix',$this->UA)) |
---|
300 | { |
---|
301 | $this->PLATFORM = 'Unix'; |
---|
302 | $this->OS = 'reliant'; |
---|
303 | } |
---|
304 | |
---|
305 | // DEC |
---|
306 | if(eregi('dec',$this->UA) || |
---|
307 | eregi('osfl',$this->UA) || |
---|
308 | eregi('alphaserver',$this->UA) || |
---|
309 | eregi('ultrix',$this->UA) || |
---|
310 | eregi('alphastation',$this->UA)) |
---|
311 | { |
---|
312 | $this->PLATFORM = 'Unix'; |
---|
313 | $this->OS = 'dec'; |
---|
314 | } |
---|
315 | |
---|
316 | // Sinix |
---|
317 | if(eregi('sinix',$this->UA)) |
---|
318 | { |
---|
319 | $this->PLATFORM = 'Unix'; |
---|
320 | $this->OS = 'sinix'; |
---|
321 | } |
---|
322 | |
---|
323 | // FreeBSD |
---|
324 | if(eregi('freebsd',$this->UA)) |
---|
325 | { |
---|
326 | $this->PLATFORM = 'Unix'; |
---|
327 | $this->OS = 'freebsd'; |
---|
328 | } |
---|
329 | |
---|
330 | // BSD |
---|
331 | if(eregi('bsd',$this->UA)) |
---|
332 | { |
---|
333 | $this->PLATFORM = 'Unix'; |
---|
334 | $this->OS = 'bsd'; |
---|
335 | } |
---|
336 | |
---|
337 | // VMS |
---|
338 | if(eregi('vax',$this->UA) || eregi('openvms',$this->UA)) |
---|
339 | { |
---|
340 | $this->PLATFORM = 'Unix'; |
---|
341 | $this->OS = 'vms'; |
---|
342 | } |
---|
343 | |
---|
344 | // SCO |
---|
345 | if(eregi('sco',$this->UA) || eregi('unix_sv',$this->UA)) |
---|
346 | { |
---|
347 | $this->PLATFORM = 'Unix'; |
---|
348 | $this->OS = 'sco'; |
---|
349 | } |
---|
350 | |
---|
351 | // Assume JavaScript Version |
---|
352 | |
---|
353 | // make the code a bit easier to read |
---|
354 | $ie = eregi('ie',$this->NAME); |
---|
355 | $ie5 = ( eregi('ie',$this->NAME) && ($this->MAJORVER >= 5) ); |
---|
356 | $ie4 = ( eregi('ie',$this->NAME) && ($this->MAJORVER >= 4) ); |
---|
357 | $ie3 = ( eregi('ie',$this->NAME) && ($this->MAJORVER >= 3) ); |
---|
358 | |
---|
359 | $nav = eregi('netscape',$this->NAME); |
---|
360 | $nav5 = ( eregi('netscape',$this->NAME) && ($this->MAJORVER >= 5) ); |
---|
361 | $nav4 = ( eregi('netscape',$this->NAME) && ($this->MAJORVER >= 4) ); |
---|
362 | $nav3 = ( eregi('netscape',$this->NAME) && ($this->MAJORVER >= 3) ); |
---|
363 | $nav2 = ( eregi('netscape',$this->NAME) && ($this->MAJORVER >= 2) ); |
---|
364 | |
---|
365 | $opera = eregi('opera',$this->NAME); |
---|
366 | |
---|
367 | // do the assumption |
---|
368 | // update as new versions are released |
---|
369 | |
---|
370 | // Provide upward compatibilty |
---|
371 | if($nav && ($this->MAJORVER > 5)) |
---|
372 | { |
---|
373 | $this->JS = 1.4; |
---|
374 | } |
---|
375 | elseif($ie && ($this->MAJORVER > 5)) |
---|
376 | { |
---|
377 | $this->JS = 1.3; |
---|
378 | } |
---|
379 | // check existing versions |
---|
380 | elseif($nav5) |
---|
381 | { |
---|
382 | $this->JS = 1.4; |
---|
383 | } |
---|
384 | elseif(($nav4 && ($this->VERSION > 4.05)) || $ie4) |
---|
385 | { |
---|
386 | $this->JS = 1.3; |
---|
387 | } |
---|
388 | elseif(($nav4 && ($this->VERSION <= 4.05)) || $ie4) |
---|
389 | { |
---|
390 | $this->JS = 1.2; |
---|
391 | } |
---|
392 | elseif($nav3 || $opera) |
---|
393 | { |
---|
394 | $this->JS = 1.1; |
---|
395 | } |
---|
396 | elseif(($nav && ($this->MAJORVER >= 2)) || ($ie && ($this->MAJORVER >=3))) |
---|
397 | { |
---|
398 | $this->JS = 1.0; |
---|
399 | } |
---|
400 | //no idea |
---|
401 | else |
---|
402 | { |
---|
403 | $this->JS = 0.0; |
---|
404 | } |
---|
405 | |
---|
406 | // Grab IP Address |
---|
407 | $this->IP = getenv('REMOTE_ADDR'); |
---|
408 | } |
---|
409 | } |
---|