"2000",
"NT 5.1" => "XP",
"NT 5.2" => "Server 2003",
"NT 6.0" => "Vista",
"NT 6.1" => "7",
"NT 6.2" => "8",
"NT 6.3" => "8.1",
"NT 10.0" => "10",
);
static $StatOrder = array(
'type' => "Device Types",
'browser' => "Desktop Browsers",
'engine' => "Browser Engines",
'chromever' => "Chrome Versions",
'blinkver' => "Chromium/Blink Engine Versions",
'ffver' => "Firefox Versions",
'iever' => "Internet Explorer Versions",
'desktopOS' => "Desktop Operating Systems",
'winver' => "Windows Versions",
'osxver' => "Mac OS X Versions",
'linuxdist' => "Linux Distributions",
'bits' => "Desktop Architectures",
'mobileOS' => "Mobile Operating Systems",
'androidver' => "Android Versions",
'androiddev' => "Android Devices",
'androidbrowser' => "Android Browsers",
'iosver' => "iOS Versions",
'iosdev' => "iOS Device Families",
'winphonever' => "Windows Phone Versions",
'winphonedev' => "Windows Phone Devices",
);
static function ver1($x) {
return explode('.', $x)[0];
}
static function ver2($x) {
return implode('.', array_slice(explode('.', $x), 0, 2));
}
function BrowserStats() {
$this->stats = array();
}
function enter($a) {
$item = array();
preg_match_all('/([A-Za-z]+)\/([0-9A-Z._+-]+)/', $a, $m, PREG_SET_ORDER);
$ver = array();
foreach ($m as $x) {
$ver[$x[1]] = $x[2];
}
# main mobile OS and desktop browser detection
if (strstr($a, "iPad;")) {
$item['type'] = "Mobile";
$item['mobileOS'] = "iOS";
$item['iosdev'] = "iPad";
} else if (strstr($a, "iPhone;")) {
$item['type'] = "Mobile";
$item['mobileOS'] = "iOS";
$item['iosdev'] = "iPhone";
} else if (preg_match('/Android[ \/]([0-9.]+);/', $a, $m)) {
$item['type'] = "Mobile";
$item['mobileOS'] = "Android";
$item['androidver'] = self::ver2($m[1]);
if (preg_match('/Android[^;]+;(.*)Build/', $a, $m)) {
$m = explode(';', $m[1]);
$m = explode('/', $m[count($m) - 1]);
$item['androiddev'] = trim($m[0]);
} else if (preg_match('/Android[^;]+;([^);]+)/', $a, $m)) {
$item['androiddev'] = trim($m[1]);
} else {
$item['androiddev'] = NULL;
}
if (isset($ver["OPR"])) {
$item['androidbrowser'] = "Opera";
} else if (isset($ver["SamsungBrowser"])) {
$item['androidbrowser'] = "Samsung Browser";
} else {
$item['androidbrowser'] = NULL;
}
} else if (preg_match('/Windows Phone ([0-9.]+)(.*)\)/', $a, $m)) {
$item['type'] = "Mobile";
$item['mobileOS'] = "Windows Phone";
$item['winphonever'] = $m[1];
$m = explode(';', $m[2]);
$item['winphonedev'] = trim($m[count($m) - 1]);
} else if (strstr($a, "Mobile")) {
$item['type'] = "Mobile";
$item['mobileOS'] = NULL;
} else if (isset($ver["Edge"]) || isset($ver["Edg"])) {
$item['type'] = "Desktop";
$item['browser'] = "Edge";
} else if (isset($ver["Opera"])) {
$item['type'] = "Desktop";
$item['browser'] = "Opera";
} else if (isset($ver["OPR"])) {
$item['type'] = "Desktop";
$item['browser'] = "Opera";
} else if (isset($ver["Vivaldi"])) {
$item['type'] = "Desktop";
$item['browser'] = "Vivaldi";
} else if (isset($ver["Iceweasel"])) {
$item['type'] = "Desktop";
$item['browser'] = "Firefox";
$item['ffver'] = self::ver1($ver["Iceweasel"]);
$item['desktopOS'] = "Linux";
$item['linuxdist'] = "Debian";
} else if (isset($ver["Firefox"])) {
$item['type'] = "Desktop";
$item['browser'] = "Firefox";
$item['ffver'] = self::ver1($ver["Firefox"]);
} else if (preg_match('/MSIE[ \/]([0-9.]+)/', $a, $m)) {
$item['type'] = "Desktop";
$item['browser'] = "Internet Explorer";
$item['iever'] = $m[1];
} else if (preg_match('/Trident\/[0-9.]+;[^)]+rv:([0-9.]+)/', $a, $m)) {
$item['type'] = "Desktop";
$item['browser'] = "Internet Explorer";
$item['iever'] = $m[1];
} else if (isset($ver["Chrome"])) {
$item['type'] = "Desktop";
$item['browser'] = "Chrome";
$item['chromever'] = self::ver1($ver["Chrome"]);
} else if (isset($ver["Safari"])) {
$item['type'] = "Desktop";
$item['browser'] = "Safari";
} else {
$item['type'] = NULL;
$item['browser'] = NULL;
}
# browser engine
if (strstr($a, "Presto/")) {
$item['engine'] = "Presto";
} else if (strstr($a, "Trident/")) {
$item['engine'] = "Trident";
} else if (strstr($a, "WebKit/")) {
$item['engine'] = "WebKit";
} else if (strstr($a, "KHTML")) {
$item['engine'] = "KHTML";
} else if (strstr($a, "Gecko/")) {
$item['engine'] = "Gecko";
} else {
$item['engine'] = NULL;
}
if (isset($ver["Chromium"])) {
$item['blinkver'] = self::ver1($ver["Chromium"]);
} else if (isset($ver["Chrome"])) {
$item['blinkver'] = self::ver1($ver["Chrome"]);
}
# desktop operating system and bitness
$desktop = ($item['type'] == "Desktop");
if (preg_match('/Windows ((NT )?[0-9.]+)[;)]/', $a, $m)) {
$item['desktopOS'] = "Windows";
$item['winver'] = isset(self::$WindowsVersionMap[$m[1]]) ? self::$WindowsVersionMap[$m[1]] : $m[1];
$item['bits'] = (strstr($a, "WOW64") || strstr($a, "x64")) ? "64-bit" : "32-bit";
} else if (preg_match('/Mac OS X ([0-9_.]+)[;)]/', $a, $m)) {
$item['desktopOS'] = "Mac OS X";
$item['osxver'] = self::ver2(str_replace('_', '.', $m[1]));
} else if ($desktop && preg_match('/Linux([^;)]*)[;)]/', $a, $m)) {
$item['desktopOS'] = "Linux";
if (strstr($a, "Ubuntu")) {
$item['linuxdist'] = "Ubuntu";
} else if (!isset($item['linuxdist'])) {
$item['linuxdist'] = NULL;
}
$m = trim($m[1]);
if (($m == "x86_64") || ($m == "amd64")) {
$item['bits'] = "64-bit";
} else if (preg_match('/^(i[3456]|x)86$/', $m, $m)) {
$item['bits'] = "32-bit";
} else {
$item['bits'] = NULL;
}
} else if ($desktop) {
$item['desktopOS'] = NULL;
}
# iOS version
if (isset($item['mobileOS']) && ($item['mobileOS'] == "iOS")) {
if (preg_match('/CPU(.*)OS ([0-9_.]+)/', $a, $m)) {
$item['iosver'] = self::ver2(str_replace('_', '.', $m[2]));
} else {
$item['iosver'] = NULL;
}
}
# add to statistics
foreach ($item as $group => $value) {
if (!isset($this->stats, $group)) {
$this->stats[$group] = array();
}
if (isset($this->stats[$group][$value])) {
$this->stats[$group][$value]++;
} else {
$this->stats[$group][$value] = 1;
}
}
}
function gen_group_start($title) {
echo "$title
\n";
echo "\n";
}
function gen_item($title, $percent) {
printf("
\n", $percent, $title ? $title : "Unknown/Other");
}
function gen_group_end() {
echo "%.1f%% %s
\n"; } EndPage(); CloseDB(); ?>