[2] | 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 |
---|
[5928] | 78 | if ( preg_match( '/MSIE ([0-9].[0-9a-zA-Z]{1,4})/i',$this->UA,$info) || |
---|
| 79 | preg_match( '/Microsoft Internet Explorer ([0-9].[0-9a-zA-Z]{1,4})/i',$this->UA,$info) ) |
---|
[2] | 80 | { |
---|
| 81 | $this->VERSION = $info[1]; |
---|
| 82 | $this->NAME = 'IE'; |
---|
| 83 | } |
---|
[5928] | 84 | elseif ( preg_match( '/Opera ([0-9].[0-9a-zA-Z]{1,4})/i',$this->UA,$info) || |
---|
| 85 | preg_match( '/Opera\/([0-9].[0-9a-zA-Z]{1,4})/i',$this->UA,$info) ) |
---|
[2] | 86 | { |
---|
| 87 | $this->VERSION = $info[1]; |
---|
| 88 | $this->NAME = 'Opera'; |
---|
| 89 | } |
---|
[5928] | 90 | elseif ( preg_match( '/iCab ([0-9].[0-9a-zA-Z]{1,4})/i',$this->UA,$info) || |
---|
| 91 | preg_match( '/iCab\/([0-9].[0-9a-zA-Z]{1,4})/i',$this->UA,$info) ) |
---|
[2] | 92 | { |
---|
| 93 | $this->VERSION = $info[1]; |
---|
| 94 | $this->NAME = 'iCab'; |
---|
| 95 | } |
---|
[5928] | 96 | elseif ( preg_match( '/Netscape6\/([0-9].[0-9a-zA-Z]{1,4})/i',$this->UA,$info) ) |
---|
[2] | 97 | { |
---|
| 98 | $this->VERSION = $info[1]; |
---|
| 99 | $this->NAME = 'Netscape'; |
---|
| 100 | } |
---|
[5928] | 101 | elseif ( preg_match( '/Mozilla\/([0-9].[0-9a-zA-Z]{1,4})/i',$this->UA,$info) ) |
---|
[2] | 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 |
---|
[5928] | 113 | if( preg_match( '/aol/i',$this->UA,$info)) |
---|
[2] | 114 | { |
---|
| 115 | $this->AOL = true; |
---|
| 116 | } |
---|
[5928] | 117 | elseif( preg_match( '/webtv/i',$this->UA,$info)) |
---|
[2] | 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 |
---|
[5928] | 140 | if( preg_match('/Win16/i',$this->UA) || |
---|
| 141 | preg_match('/windows 3.1/i',$this->UA) || |
---|
| 142 | preg_match('/windows 16-bit/i',$this->UA) || |
---|
| 143 | preg_match('/16bit/i',$this->UA)) |
---|
[2] | 144 | { |
---|
| 145 | $this->PLATFORM = 'Win16'; |
---|
| 146 | $this->OS = 'Win31'; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | // Check for Windows 32-bit |
---|
[5928] | 150 | if(preg_match('/Win95/i',$this->UA) || preg_match('/windows 95/i',$this->UA)) |
---|
[2] | 151 | { |
---|
| 152 | $this->PLATFORM = 'Win32'; |
---|
| 153 | $this->OS = 'Win95'; |
---|
| 154 | } |
---|
[5928] | 155 | elseif(preg_match('/Win98/i',$this->UA) || preg_match('/windows 98/i',$this->UA)) |
---|
[2] | 156 | { |
---|
| 157 | $this->PLATFORM = 'Win32'; |
---|
| 158 | $this->OS = 'Win98'; |
---|
| 159 | } |
---|
[5928] | 160 | elseif(preg_match('/WinNT/i',$this->UA) || preg_match('/windows NT/i',$this->UA)) |
---|
[2] | 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 |
---|
[5928] | 172 | if( preg_match('/os\/2/i',$this->UA) || preg_match('/ibm-webexplorer/i',$this->UA)) |
---|
[2] | 173 | { |
---|
| 174 | $this->PLATFORM = 'OS2'; |
---|
| 175 | $this->OS = 'OS2'; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | // Check for Mac 68000 |
---|
[5928] | 179 | if( preg_match('/68k/i',$this->UA) || preg_match('/68000/i',$this->UA)) |
---|
[2] | 180 | { |
---|
| 181 | $this->PLATFORM = 'Mac'; |
---|
| 182 | $this->OS = 'Mac68k'; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | //Check for Mac PowerPC |
---|
[5928] | 186 | if( preg_match('/ppc/i',$this->UA) || preg_match('/powerpc/i',$this->UA)) |
---|
[2] | 187 | { |
---|
| 188 | $this->PLATFORM = 'Mac'; |
---|
| 189 | $this->OS = 'MacPPC'; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | // Check for Unix Flavor |
---|
| 193 | |
---|
| 194 | //SunOS |
---|
[5928] | 195 | if(preg_match('/sunos/i',$this->UA)) |
---|
[2] | 196 | { |
---|
| 197 | $this->PLATFORM = 'Unix'; |
---|
| 198 | $this->OS = 'sun'; |
---|
| 199 | } |
---|
[5928] | 200 | if(preg_match('/sunos 4/i',$this->UA)) |
---|
[2] | 201 | { |
---|
| 202 | $this->PLATFORM = 'Unix'; |
---|
| 203 | $this->OS = 'sun4'; |
---|
| 204 | } |
---|
[5928] | 205 | elseif(preg_match('/sunos 5/i',$this->UA)) |
---|
[2] | 206 | { |
---|
| 207 | $this->PLATFORM = 'Unix'; |
---|
| 208 | $this->OS = 'sun5'; |
---|
| 209 | } |
---|
[5928] | 210 | elseif(preg_match('/i86/i',$this->UA)) |
---|
[2] | 211 | { |
---|
| 212 | $this->PLATFORM = 'Unix'; |
---|
| 213 | $this->OS = 'suni86'; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | // Irix |
---|
[5928] | 217 | if(preg_match('/irix/',$this->UA)) |
---|
[2] | 218 | { |
---|
| 219 | $this->PLATFORM = 'Unix'; |
---|
| 220 | $this->OS = 'irix'; |
---|
| 221 | } |
---|
[5928] | 222 | if(preg_match('/irix 6/i',$this->UA)) |
---|
[2] | 223 | { |
---|
| 224 | $this->PLATFORM = 'Unix'; |
---|
| 225 | $this->OS = 'irix6'; |
---|
| 226 | } |
---|
[5928] | 227 | elseif(preg_match('/irix 5/i',$this->UA)) |
---|
[2] | 228 | { |
---|
| 229 | $this->PLATFORM = 'Unix'; |
---|
| 230 | $this->OS = 'irix5'; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | //HP-UX |
---|
[5928] | 234 | if(preg_match('/hp-ux/i',$this->UA)) |
---|
[2] | 235 | { |
---|
| 236 | $this->PLATFORM = 'Unix'; |
---|
| 237 | $this->OS = 'hpux'; |
---|
| 238 | } |
---|
[5928] | 239 | if(preg_match('/hp-ux/i',$this->UA) && preg_match('/10./',$this-UA)) |
---|
[2] | 240 | { |
---|
| 241 | $this->PLATFORM = 'Unix'; |
---|
| 242 | $this->OS = 'hpux10'; |
---|
| 243 | } |
---|
[5928] | 244 | elseif(preg_match('/hp-ux/i',$this->UA) && preg_match('/09./',$this-UA)) |
---|
[2] | 245 | { |
---|
| 246 | $this->PLATFORM = 'Unix'; |
---|
| 247 | $this->OS = 'hpux9'; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | //AIX |
---|
[5928] | 251 | if(preg_match('/aix/i',$this->UA)) |
---|
[2] | 252 | { |
---|
| 253 | $this->PLATFORM = 'Unix'; |
---|
| 254 | $this->OS = 'aix'; |
---|
| 255 | } |
---|
[5928] | 256 | if(preg_match('/aix1/i',$this->UA)) |
---|
[2] | 257 | { |
---|
| 258 | $this->PLATFORM = 'Unix'; |
---|
| 259 | $this->OS = 'aix1'; |
---|
| 260 | } |
---|
[5928] | 261 | elseif(preg_match('/aix2/i',$this->UA)) |
---|
[2] | 262 | { |
---|
| 263 | $this->PLATFORM = 'Unix'; |
---|
| 264 | $this->OS = 'aix2'; |
---|
| 265 | } |
---|
[5928] | 266 | elseif(preg_match('/aix3/i',$this->UA)) |
---|
[2] | 267 | { |
---|
| 268 | $this->PLATFORM = 'Unix'; |
---|
| 269 | $this->OS = 'aix3'; |
---|
| 270 | } |
---|
[5928] | 271 | elseif(preg_match('/aix4/i',$this->UA)) |
---|
[2] | 272 | { |
---|
| 273 | $this->PLATFORM = 'Unix'; |
---|
| 274 | $this->OS = 'aix4'; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | // Linux |
---|
[5928] | 278 | if(preg_match('/inux/i',$this->UA)) |
---|
[2] | 279 | { |
---|
| 280 | $this->PLATFORM = 'Unix'; |
---|
| 281 | $this->OS = 'linux'; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | //Unixware |
---|
[5928] | 285 | if(preg_match('/unix_system_v/i',$this->UA)) |
---|
[2] | 286 | { |
---|
| 287 | $this->PLATFORM = 'Unix'; |
---|
| 288 | $this->OS = 'unixware'; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | //mpras |
---|
[5928] | 292 | if(preg_match('/ncr/i',$this->UA)) |
---|
[2] | 293 | { |
---|
| 294 | $this->PLATFORM = 'Unix'; |
---|
| 295 | $this->OS = 'mpras'; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | //Reliant |
---|
[5928] | 299 | if(preg_match('/reliantunix/i',$this->UA)) |
---|
[2] | 300 | { |
---|
| 301 | $this->PLATFORM = 'Unix'; |
---|
| 302 | $this->OS = 'reliant'; |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | // DEC |
---|
[5928] | 306 | if(preg_match('/dec/i',$this->UA) || |
---|
| 307 | preg_match('/osfl/i',$this->UA) || |
---|
| 308 | preg_match('/alphaserver/i',$this->UA) || |
---|
| 309 | preg_match('/ultrix/i',$this->UA) || |
---|
| 310 | preg_match('/alphastation/i',$this->UA)) |
---|
[2] | 311 | { |
---|
| 312 | $this->PLATFORM = 'Unix'; |
---|
| 313 | $this->OS = 'dec'; |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | // Sinix |
---|
[5928] | 317 | if(preg_match('/sinix/i',$this->UA)) |
---|
[2] | 318 | { |
---|
| 319 | $this->PLATFORM = 'Unix'; |
---|
| 320 | $this->OS = 'sinix'; |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | // FreeBSD |
---|
[5928] | 324 | if(preg_match('/freebsd/i',$this->UA)) |
---|
[2] | 325 | { |
---|
| 326 | $this->PLATFORM = 'Unix'; |
---|
| 327 | $this->OS = 'freebsd'; |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | // BSD |
---|
[5928] | 331 | if(preg_match('/bsd/i',$this->UA)) |
---|
[2] | 332 | { |
---|
| 333 | $this->PLATFORM = 'Unix'; |
---|
| 334 | $this->OS = 'bsd'; |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | // VMS |
---|
[5928] | 338 | if(preg_match('/vax/i',$this->UA) || preg_match('/openvms/i',$this->UA)) |
---|
[2] | 339 | { |
---|
| 340 | $this->PLATFORM = 'Unix'; |
---|
| 341 | $this->OS = 'vms'; |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | // SCO |
---|
[5928] | 345 | if(preg_match('/sco/i',$this->UA) || preg_match('/unix_sv/i',$this->UA)) |
---|
[2] | 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 |
---|
[5928] | 354 | $ie = preg_match('/ie/i',$this->NAME); |
---|
| 355 | $ie5 = ( preg_match('/ie/i',$this->NAME) && ($this->MAJORVER >= 5) ); |
---|
| 356 | $ie4 = ( preg_match('/ie/i',$this->NAME) && ($this->MAJORVER >= 4) ); |
---|
| 357 | $ie3 = ( preg_match('/ie/i',$this->NAME) && ($this->MAJORVER >= 3) ); |
---|
[2] | 358 | |
---|
[5928] | 359 | $nav = preg_match('/netscape/i',$this->NAME); |
---|
| 360 | $nav5 = ( preg_match('/netscape/i',$this->NAME) && ($this->MAJORVER >= 5) ); |
---|
| 361 | $nav4 = ( preg_match('/netscape/i',$this->NAME) && ($this->MAJORVER >= 4) ); |
---|
| 362 | $nav3 = ( preg_match('/netscape/i',$this->NAME) && ($this->MAJORVER >= 3) ); |
---|
| 363 | $nav2 = ( preg_match('/netscape/i',$this->NAME) && ($this->MAJORVER >= 2) ); |
---|
[2] | 364 | |
---|
[5928] | 365 | $opera = preg_match('/opera/i',$this->NAME); |
---|
[2] | 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 | } |
---|