File: SniffBrowser.php

package info (click to toggle)
opendb 0.81p18-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,716 kB
  • ctags: 6,787
  • sloc: php: 50,213; sql: 3,098; sh: 272; makefile: 54; xml: 48
file content (72 lines) | stat: -rw-r--r-- 2,411 bytes parent folder | download | duplicates (2)
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
<?php
/*
   This function is a browser sniffer that returns a string-indexed array.
   The call:
      $browser = SniffBrowser();
   will return the following:
   $browser['type'] = Netscape, Explorer, Opera, Amaya, Unknown
   $browser['version'] = version number (float)
   $browser['platform'] = Windows, Mac, Other
   $browser['css'] = CSS version
   $browser['dom'] = DOM type: NS, IE, W3C, 0

   Sourced from http://www.eit.ihk-edu.dk/instruct/php-sniffer.php?e=0,7,22#0

   I am not sure of the copyright details for this function...
*/
function SniffBrowser()
{
   global $HTTP_USER_AGENT;
   $b = $HTTP_USER_AGENT; $vers = 0.0;

   // detect browser brand and version number
   if (eregi('Opera[ \/]([0-9\.]+)' , $b, $a)) {
      $type = 'Opera';}
   elseif (eregi('Netscape[[:alnum:]]*[ \/]([0-9\.]+)', $b, $a)) {
      $type = 'Netscape';}
   elseif (eregi('MSIE[ \/]([0-9\.]+)', $b, $a)) {
      $type = 'Explorer';}
   elseif (eregi('Mozilla[ \/]([0-9\.]+)' , $b, $a)) {
      if (eregi('compatible' , $b)) {
         $type = 'Unknown';}
      else {
         $type = 'Netscape';}}
   elseif (eregi('([[:alnum:]]+)[ \/v]*([0-9\.]+)' , $b, $a)) {
      $type = $a[1]; $vers = $a[2];}
   else {
      $type = 'Unknown';}
   if (!$vers) $vers = $a[1];
   $browser['type'] = $type;
   $browser['version'] = $vers;

   // detect platform
   if (eregi('Win',$b)) $browser['platform'] = 'Windows';
   elseif (eregi('Mac',$b)) $browser['platform'] = 'Mac';
   else $browser['platform'] = 'Other';

   // find CSS version
   // note: it is unknown which future versions will support CSS2
   if ($type == 'Netscape' && $vers >= 4 ||
   $type == 'Explorer' && $vers >= 3 ||
   $type == 'Opera' && $vers >= 3) {
      $browser['css'] = 1;
      if ($type == 'Netscape' && $vers >= 5 ||
      $type == 'Explorer' && $vers >= 6 ||
      $type == 'Opera' && $vers >= 4) {
         $browser['css'] = 2;}}

   // detect DOM version
   $browser['dom'] = '0';
   if ($type == 'Explorer' && $vers >= 4 && $browser['platform'] == 'Windows') {
      // note: it is unknown which DOM model future versions of Explorer will use
      $browser['dom'] = 'IE';}
   elseif ($type == 'Opera' && $vers >= 5) {
      $browser['dom'] = 'W3C';}
   elseif ($type == 'Netscape') {
      if ($vers >= 5) $browser['dom'] = 'W3C';
      elseif ($vers >= 4) $browser['dom'] = 'NS';}

   // return array of answers
   return $browser;
}
?>