Here is 1 solution for determining browser by user agent and storing it as an xml file. This doesn't store OS or browser versions. If you want that alterations could be made to it as well.
PHP Code:
<?php
//Credit or more info http://php.net/manual/en/function.get-browser.php
function browser_info($agent=null) {
// Declare known browsers to look for
$known = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape',
'konqueror', 'gecko');
// Clean up agent and build regex that matches phrases for known browsers
// (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor
// version numbers. E.g. "2.0.0.6" is parsed as simply "2.0"
$agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']);
$pattern = '#(?<browser>' . join('|', $known) .
')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#';
// Find all phrases (or return empty array if none found)
if (!preg_match_all($pattern, $agent, $matches)) return array();
// Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase,
// Opera 7,8 have a MSIE phrase), use the last one found (the right-most one
// in the UA). That's usually the most correct.
$i = count($matches['browser'])-1;
return array($matches['browser'][$i] => $matches['version'][$i]);
}
$ua = browser_info();
if ($ua['firefox']) {
$browser = "Firefox";
}
if ($ua['msie']) {
$browser = "IE";
}
if ($ua['opera']) {
$browser = "Opera";
}
if ($ua['safari']) {
$browser = "Safari";
}
$stat_file = "browser.xml";
$stats = file_get_contents($stat_file);
$stats_are = explode ("<" . $browser . ">",$stats);
$stats_are = explode ("</" . $browser . ">", $stats_are[1]);
$value = $stats_are[0] + 1;
$patterns = array();
$patterns[0] = '/<' . "$browser" . '>(.*)' ."<\/$browser>" . '/';
$replacements = array();
$replacements[0] = "<$browser>$value</$browser>";
$output = preg_replace($patterns, $replacements, $stats);
file_put_contents($stat_file, $output);
?>
Browser.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Browsers>
<Firefox>0</Firefox>
<Safari>0</Safari>
<IE>0</IE>
<Chrome>0</Chrome>
<Opera>0</Opera>
</Browsers>
Bookmarks