A
download PHPClientSniffer.inc
Language: NonCode
LOC: 0
Project Info
HPE
Server: SourceForge
Type: cvs
...ceForge\h\hpe\hpe\hpe1\HPE\
   .cvsignore
   clickerr.inc
   config.inc
   Config_File.class.php
   database.inc
   database.mysql.inc
   database.pear.inc
   FormChek.js
   HPE.inc
   HPEbase.inc
   HPEUsers.default.xml
   HPEUsers.guest.xml
   layout.js
   local.inc
   modules.inc
   ...andlers.addChannel.ftsc
   navcond.js
   newsaccess.inc
   newssource.inc
   newstools.js
   overlib.js
   overlib_mini.js
   pagemaker.inc
   pages.inc
   PHPClientSniffer.inc
   phpodp.inc
   publisher.inc
   services.inc
   sitelister.inc
   Smarty.addons.php
   Smarty.class.php
   Smarty_Compiler.class.php
   sourcetools.js
   thememaker.inc
   toparser.inc
   user.edit.inc
   user.inc
   xmlrpc.inc
   xmlrpcs.inc
   xmltree.inc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<?php

/******************************************
** Description   : PHPClientSniffer
** Version       : 1.2.5
** File Name     : PHPClientSniffer.php3
** Author        : Roger Raymond for PHyX8 studios
** Author Email  : roger.raymond@asphyxia.com
** Created       : Wednesday, August 23, 2000
** Last Modified : Saturday, December 16, 2000
** Modified By   : Roger Raymond
*'
   INFO:
   Returns client information based on HTTP_USER_AGENT

   BASED ON WORKS AND IDEAS BY:
   Tim Perdue of PHPBuilder.com
   http://www.phpbuilder.com/columns/tim20000821.php3

   The Ultimate JavaScript Client Sniffer by Netscape.
   http://developer.netscape.com/docs/examples/javascript/browser_type.html

   ========================================================================
   USAGE:
   ========================================================================
   include("PHPClientSniffer.php3");
   // to use current HTTP_USER_AGENT string
   $is = new sniffer();
   // to use OPTIONALLY SUPPLIED HTTP_USER_AGENT string
   $is = new sniffer("Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001209");

   ** This call must be made before any HTTP HEADERS are sent.

   ========================================================================
   USER DEFINABLE VARIABLES
   ========================================================================
   $CHECK_FOR_COOKIES = true/false
      Defines whether or not the Cookie Checking Routine is active.  If
      it is set to FALSE, the $is->COOKIES variable will return FALSE.

   ========================================================================
   VARIABLE NAMES    VALUES
   ========================================================================
   $is->UA           The HTTP USER AGENT String
   $is->BROWSER      Browser Name (Netscape, IE, Opera, iCab, Lynx, Unknown)
   $is->VERSION      Browser Full Version
   $is->MAJORVER     Browser Major Version
   $is->MINORVER     Browser Minor Version
   $is->JS           Assumed JavaScript Version Supported by Browser
   $is->PLATFORM     System Platform (Win16,Win32,Mac,OS2,Unix)
   $is->OS           System OS (Win98,OS2,Mac68k,linux,bsd,etc...) see code
   $is->IP           REMOTE_ADDR

   ========================================================================
   QUICK TESTS       TRUE/FALSE
   ========================================================================
   $is->COOKIES      Client accepts cookies
   $is->AOL          America Online
   $is->WEBTV        WebTV
   $is->LYNX         Lynx Browser
   $is->KONQUEROR    KDE Konqueror Browser
   $is->IE           Internet Explorer
   $is->IE5          Internet Explorer Version 5
   $is->IE5up        Internet Explorer Version 5 and up
   $is->IE4          Internet Explorer Version 4
   $is->IE4up        Internet Explorer Version 4 and up
   $is->IE3          Internet Explorer Version 3
   $is->IE3up        Internet Explorer Version 3 and up
   $is->IE2          Internet Explorer Version 2
   $is->IE2up        Internet Explorer Version 2 and up
   $is->NS           Netscape Navigator
   $is->NS6          Netscape Navigator Version 6
   $is->NS6up        Netscape Navigator Version 6 and up
   $is->NS5          Netscape Navigator Version 5
   $is->NS5up        Netscape Navigator Version 5 and up
   $is->NS4          Netscape Navigator Version 4
   $is->NS4up        Netscape Navigator Version 4 and up
   $is->NS3          Netscape Navigator Version 3
   $is->NS3up        Netscape Navigator Version 3 and up
   $is->NS2          Netscape Navigator Version 2
   $is->NS2up        Netscape Navigator Version 2 and up
   $is->OP           Opera
   $is->OP5          Opera Version 5
   $is->OP5up        Opera Version 5 and up
   $is->OP4          Opera Version 4
   $is->OP4up        Opera Version 4 and up
   $is->OP3          Opera Version 3
   $is->OP3up        Opera Version 3 and up

   ========================================================================
   LANGUAGES
   ========================================================================
   $is->LANGUAGE     ARRAY of Language(s) accepted by the user's browser

   ========================================================================
   HISTORY:
   ========================================================================
   Saturday, December 16, 2000
      +  Konqueror HTTP_USER_AGENT String tested and working
      +  Initialized $OP5 and $OP5up as FALSE
      +  Pending : sniff of Win2k and JS Versions of Konqueror, etc...

   Thursday, December 14, 2000
      +  constructor now accepts optional HTTP_USER_AGENT string
      +  Opera 5.0 will report as supporting JavaScript 1.3
      +  Added Opera 5 Quick Checks
         $is->OP5
         $is->OP5up
      +  Added support for KDE Konqueror Browser (untested)
      ***NOTES
         This is not yet tested, but should at least detect the browser
         (assuming it used a standard HTTP_USER_AGENT string.)
         Anyone that can send a UA string to me would be doing me a great
         service.  Also, a mention on the actual version of JavaScript that
         is supported by this browser would also be welcomed.

   Thursday, September 21, 2000
      +  Added Check for Lynx browser ($is->LYNX)
      ***NOTES
         Lynx does not have informative User Agent strings
         by default.  The most you can get out of a default
         User Agent string for Lynx is the Browser Name and
         Major and Minor versions.

   Wednesday, September 20, 2000
      +  Added QuickTests
         Wanna know if it's Netscape 4 or IE 4+?
         Just check if($is->NS4 || $is->IE4up)
      + fixed $is->LANGUAGE detection routine
      + fixed $is->COOKIES check in Netscape and IE

   Friday, September 01, 2000
      +  Added HTTP_ACCEPT_LANGUAGE support
         $is->LANGUAGE Array

   Wednesday, August 31, 2000
   ** This is a maintenance release. You do not need to replace
      version 1.1.0 with version 1.1.1 unless you really want to.

      +  Shortened the Cookie Check Routine.
         Replaced multiple lines with one line of code.
      +  Added $CHECK_FOR_COOKIES user definable variable.
         default value is TRUE.

   Wednesday, August 30, 2000
      +  Added Cookie Check
      +  Renamed $is->NAME to $is->BROWSER

 '****************************************/
class sniffer
{  // USER DEFINABLE VARIABLES
   var $CHECK_FOR_COOKIES = false;   // toggle cookie checking

   // VARIABLES SET AND RETURNED BY CLIENT SNIFFER
   // YOU DO NOT NEED TO MODIFY BELOW THIS LINE
   // =====================================================================
   var $UA         =  "";
   var $BROWSER    =  "Unknown";
   var $VERSION    =  0;
   var $MAJORVER   =  0;
   var $MINORVER   =  0;
   var $JS         =  0.0;
   var $PLATFORM   =  "Unknown";
   var $OS         =  "Unknown";
   var $IP         =  "Unknown";
   var $LANGUAGE   =  "";
   // QUICK TEST VARIABLES
   // =====================================================================
   var $COOKIES    =  false;
   var $AOL        =  false;
   var $WEBTV      =  false;
   //__________[Lynx]
   var $LYNX       =  false;
   //__________[Konqueror]
   var $KONQUEROR  =  false;
   //__________[Microsoft Internet Explorer]
   var $IE         =  false;
   var $IE5        =  false;
   var $IE5up      =  false;
   var $IE4        =  false;
   var $IE4up      =  false;
   var $IE3        =  false;
   var $IE3up      =  false;
   var $IE2        =  false;
   var $IE2up      =  false;
   //__________[Netscape Navigator]
   var $NS         =  false;
   var $NS6        =  false;
   var $NS6up      =  false;
   var $NS5        =  false;
   var $NS5up      =  false;
   var $NS4        =  false;
   var $NS4up      =  false;
   var $NS3        =  false;
   var $NS3up      =  false;
   var $NS2        =  false;
   var $NS2up      =  false;
   //__________[Opera]
   var $OP         =  false;
   var $OP5        =  false;
   var $OP5up      =  false;
   var $OP4        =  false;
   var $OP4up      =  false;
   var $OP3        =  false;
   var $OP3up      =  false;


   /* START CONSTRUCTOR */
   function sniffer($UA="")
   {  if(empty($UA)) $this->UA = getenv("HTTP_USER_AGENT");
      else $this->UA = $UA;

      global $ctest;
      global $testcookie;
      global $PHP_SELF;

      // Test For Cookies if enabled
      if($this->CHECK_FOR_COOKIES)
      {  if ($ctest != 1)
         {  SetCookie("testcookie","test",time()+3600,"/");
            // See if we were passed anything in the QueryString we might need
            $QS = getenv("QUERY_STRING");
            $location = $PHP_SELF.($QS=="" ? "?ctest=1" : "?".$QS."&ctest=1");
            header("Location: $location");
            exit;
         }
         // Check for the cookie on page reload
         elseif ($testcookie == "test") $this->COOKIES = true;
         else $this->COOKIES = false;
      }
      else $this->COOKIES = false;

      // Determine Browser Name and Version
      if ( eregi( 'MSIE ([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) ||
           eregi( 'Microsoft Internet Explorer ([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) )
      {  $this->VERSION = $info[1];
         $this->BROWSER = 'IE';
      }
      elseif ( eregi( 'Opera ([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) ||
               eregi( 'Opera/([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) )
      {  $this->VERSION = $info[1];
         $this->BROWSER = 'Opera';
      }
      elseif ( eregi( 'iCab ([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) ||
               eregi( 'iCab/([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) )
      {  $this->VERSION = $info[1];
         $this->BROWSER = 'iCab';
      }
      elseif ( eregi( 'Lynx ([0-9].[0-9a-zA-Z.]{1,9})',$this->UA,$info) ||
               eregi( 'Lynx/([0-9].[0-9a-zA-Z.]{1,9})',$this->UA,$info) )
      {  $this->VERSION = $info[1];
         $this->BROWSER = 'Lynx';
         $this->LYNX = true;
      }
      elseif ( eregi( 'Konqueror ([0-9].[0-9.a-zA-Z]{1,9})',$this->UA,$info) ||
               eregi( 'Konqueror/([0-9].[0-9.a-zA-Z]{1,9})',$this->UA,$info) )
      {  $this->VERSION = $info[1];
         $this->BROWSER = 'Konqueror';
         $this->KONQUEROR = true;
      }
      elseif ( eregi( 'Netscape6/([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) )
      {  $this->VERSION = $info[1];
         $this->BROWSER = 'Netscape';
      }
      elseif ( eregi( 'Mozilla/([0-9].[0-9a-zA-Z]{1,4})',$this->UA,$info) )
      {  $this->VERSION = $info[1];
         $this->BROWSER = 'Netscape';
      }
      else
      {  $this->VERSION = 0;
         $this->BROWSER = 'Unknown';
      }

      // Determine if AOL or WEBTV
      if( eregi( 'aol',$this->UA,$info))
      { $this->AOL = true;
      }
      elseif( eregi( 'webtv',$this->UA,$info))
      { $this->WEBTV = true;
      }

      // Determine Major and Minor Version
      if($this->VERSION > 0)
      {  $pos = strpos($this->VERSION,".");
         if ($pos > 0)
         {  $this->MAJORVER = substr($this->VERSION,0,$pos);
            $this->MINORVER = substr($this->VERSION,$pos,strlen($this->VERSION));
         }
         else $this->MAJORVER = $this->VERSION;
      }

      // QUICK TESTS
      // A set of values most often sought

      // Check [Internet Explorer]
      if($this->IE      = eregi("ie",$this->BROWSER))
      {  $this->IE5     = ( $this->MAJORVER == 5 );
         $this->IE5up   = ( $this->MAJORVER >= 5 );
         $this->IE4     = ( $this->MAJORVER == 4 );
         $this->IE4up   = ( $this->MAJORVER >= 4 );
         $this->IE3     = ( $this->MAJORVER == 3 );
         $this->IE3up   = ( $this->MAJORVER >= 3 );
         $this->IE2     = ( $this->MAJORVER == 2 );
         $this->IE2up   = ( $this->MAJORVER >= 2 );
      }

      // Check [Netscape Navigator]
      if($this->NS      = eregi("netscape",$this->BROWSER))
      {  $this->NS6     = ( $this->MAJORVER == 6 );
         $this->NS6up   = ( $this->MAJORVER >= 6 );
         $this->NS5     = ( $this->MAJORVER == 5 );
         $this->NS5up   = ( $this->MAJORVER >= 5 );
         $this->NS4     = ( $this->MAJORVER == 4 );
         $this->NS4up   = ( $this->MAJORVER >= 4 );
         $this->NS3     = ( $this->MAJORVER == 3 );
         $this->NS3up   = ( $this->MAJORVER >= 3 );
         $this->NS2     = ( $this->MAJORVER == 2 );
         $this->NS2up   = ( $this->MAJORVER >= 2 );
      }

      // Check [Opera]
      if($this->OP      = eregi("opera",$this->BROWSER))
      {  $this->OP5     = ( $this->MAJORVER == 5 );
         $this->OP5up   = ( $this->MAJORVER >= 5 );
         $this->OP4     = ( $this->MAJORVER == 4 );
         $this->OP4up   = ( $this->MAJORVER >= 4 );
         $this->OP3     = ( $this->MAJORVER == 3 );
         $this->OP3up   = ( $this->MAJORVER >= 3 );
      }

      // Determine Platform and OS

      // Check for Windows 16-bit
      if( eregi('Win16',$this->UA)           ||
          eregi('windows 3.1',$this->UA)     ||
          eregi('windows 16-bit',$this->UA)  ||
          eregi('16bit',$this->UA))
      {  $this->PLATFORM = "Win16";
         $this->OS = "Win31";
      }

      // Check for Windows 32-bit
      if(eregi('Win95',$this->UA) || eregi('windows 95',$this->UA))
      {  $this->PLATFORM = "Win32";
         $this->OS = "Win95";
      }
      elseif(eregi('Win98',$this->UA) || eregi('windows 98',$this->UA))
      {  $this->PLATFORM = "Win32";
         $this->OS = "Win98";
      }
      elseif(eregi('WinNT',$this->UA) || eregi('windows NT',$this->UA))
      {  $this->PLATFORM = "Win32";
         $this->OS = "WinNT";
      }
      elseif(eregi('Win',$this->UA))
      {  $this->PLATFORM = "Win32";
         $this->OS = "Win9xNT";
      }

      // Check for OS/2
      if( eregi('os/2',$this->UA)            ||
          eregi('ibm-webexplorer',$this->UA))
      {  $this->PLATFORM = "OS2";
         $this->OS = "OS2";
      }

      // Check for Mac 68000
      if( eregi('68k',$this->UA)             ||
          eregi('68000',$this->UA))
      {  $this->PLATFORM = "Mac";
         $this->OS = "Mac68k";
      }

      //Check for Mac PowerPC
      if( eregi('ppc',$this->UA)             ||
          eregi('powerpc',$this->UA))
      {  $this->PLATFORM = "Mac";
         $this->OS = "MacPPC";
      }

      // Check for Unix Flavor

      //SunOS
      if(eregi('sunos',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "sun";
      }
      if(eregi('sunos 4',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "sun4";
      }
      elseif(eregi('sunos 5',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "sun5";
      }
      elseif(eregi('i86',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "suni86";
      }

      // Irix
      if(eregi('irix',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "irix";
      }
      if(eregi('irix 6',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "irix6";
      }
      elseif(eregi('irix 5',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "irix5";
      }

      //HP-UX
      if(eregi('hp-ux',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "hpux";
      }
      if(eregi('hp-ux',$this->UA) && ereg('10.',$this-UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "hpux10";
      }
      elseif(eregi('hp-ux',$this->UA) && ereg('09.',$this-UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "hpux9";
      }

      //AIX
      if(eregi('aix',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "aix";
      }
      if(eregi('aix1',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "aix1";
      }
      elseif(eregi('aix2',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "aix2";
      }
      elseif(eregi('aix3',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "aix3";
      }
      elseif(eregi('aix4',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "aix4";
      }

      // Linux
      if(eregi('inux',$this->UA) || eregi('X11',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "linux";
      }

      //Unixware
      if(eregi('unix_system_v',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "unixware";
      }

      //mpras
      if(eregi('ncr',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "mpras";
      }

      //Reliant
      if(eregi('reliantunix',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "reliant";
      }

      // DEC
      if(eregi('dec',$this->UA)           ||
         eregi('osfl',$this->UA)          ||
         eregi('alphaserver',$this->UA)   ||
         eregi('ultrix',$this->UA)        ||
         eregi('alphastation',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "dec";
      }

      // Sinix
      if(eregi('sinix',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "sinix";
      }

      // FreeBSD
      if(eregi('freebsd',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "freebsd";
      }

      // BSD
      if(eregi('bsd',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "bsd";
      }

      // VMS
      if(eregi('vax',$this->UA) || eregi('openvms',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "vms";
      }

      // SCO
      if(eregi('sco',$this->UA) || eregi('unix_sv',$this->UA))
      {  $this->PLATFORM = "Unix";
         $this->OS = "sco";
      }

      // Assume JavaScript Version
      // update as new versions are released
      // Provide upward compatibilty
      if($this->NS5up) $this->JS = 1.4;
      elseif($this->IE5up) $this->JS = 1.3;
      // check existing versions
      elseif($this->NS5) $this->JS = 1.4;
      elseif($this->OP5 || $this->OP5up) $this->JS = 1.3;
      elseif(($this->NS4 && ($this->VERSION > 4.05)) || $this->IE4) $this->JS = 1.3;
      elseif(($this->NS4 && ($this->VERSION <= 4.05)) || $this->IE4) $this->JS = 1.2;
      elseif($this->NS3 || $this->OP) $this->JS = 1.1;
      elseif(($this->NS && ($this->MAJORVER >= 2)) || ($this->IE && ($this->MAJORVER >=3))) $this->JS = 1.0;
      //no idea
      else $this->JS = 0.0;

      // Grab IP Address
      $this->IP = getenv('REMOTE_ADDR');

      // Determine Language(s) accepted by browser
      if($languages = getenv('HTTP_ACCEPT_LANGUAGE'))
      {  $j = strpos($languages,";");
         if($j > 0) $languages = substr($languages,0,$j);
         $languages = explode(",",$languages);
         $this->LANGUAGE = $languages;
      }
      else $this->LANGUAGE[0] = "Undefined" ;
   }
}

?>

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us