summaryrefslogtreecommitdiff
path: root/contrib/www/esc/browser.php
blob: 5df08dc44537927f096450d132123a335201baad (plain) (blame)
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
<?php
$browser = array(
  'platform'  => 'unknown',
  'name'      => 'unknown',
  'version'   => '0.0.0',
  'majorver'  => 0,
  'minorver'  => 0,
  'build'     => 0,
  'useragent' => ''
);

$browsers = array(
  'firefox', 'msie', 'opera', 'chrome', 'safari', 'mozilla', 'seamonkey', 'konqueror', 'netscape',
  'gecko', 'navigator', 'mosaic', 'lynx', 'amaya', 'omniweb', 'avant', 'camino', 'flock', 'aol'
);

if (isset($_SERVER['HTTP_USER_AGENT'])) {
  $browser['useragent'] = $_SERVER['HTTP_USER_AGENT'];
  $user_agent = strtolower($browser['useragent']);
  foreach($browsers as $_browser) {
    if (preg_match("/($_browser)[\/ ]?([0-9.]*)/", $user_agent, $match)) {
       $browser['name'] = $match[1];
       $browser['version'] = $match[2];
       @list($browser['majorver'], $browser['minorver'], $browser['build']) = explode('.', $browser['version']);
       break;
    }
  }
  if (preg_match('/linux/i', $user_agent)) {
    $browser['platform'] = 'linux';
  }
  elseif (preg_match('/macintosh|mac os x/i', $user_agent)) {
    $browser['platform'] = 'mac';
  }
  elseif (preg_match('/windows|win32/i', $user_agent)) {
    $browser['platform'] = 'windows';
  }

}

if ( isset($_GET['debug']) ) {
  echo "<pre>";
  print_r($browser);
  echo "</pre>";
}
?>