Thanks, this doesn't appear to be adding to my file though. Is there something else I need to add for it to trigger the update?
I have this now
PHP Code:
<?php
$xml = simplexml_load_file('log.xml');
$ua = $_SERVER['HTTP_USER_AGENT'];
$ip = $_SERVER['REMOTE_ADDR'];
$known = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape', 'konqueror', 'gecko');
$agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']);
$date = date('m/d/Y H:i:s');
if (preg_match('/linux/', $agent)) {
$os = "Linux";
} elseif (preg_match('/macintosh|mac os x/', $agent)) {
$os = 'Mac';
} elseif (preg_match('/windows|win32/', $agent)) {
$os = 'Windows';
} else {
$os = 'Unknown';
}
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#';
if (!preg_match_all($pattern, $agent, $matches)) return array();
$i = count($matches['browser'])-1;
$browser = ucwords($matches['browser'][$i]);
$version = $matches['version'][$i];
foreach ($xml as $visitor) {
if($visitor->ip == $ip) {
// Returning Visitor
$visitor->visits = $visitor->visits + 1;
} else {
//echo "New Visitor";
$visitor->addChild('ip', $ip);
}
}
?>
I want it to add
Code:
<visitor>
<date>$date</date>
<user_agent>$browser $version</user_agent>
<os>$os</os>
<ip>$ip</ip>
<visits>0</visits>
</visitor>
for each new user and update the visits for each returning visitor.
Tried modifying it to this but still no luck.
Code:
//echo "New Visitor";
$new_visitor = $visitor->addChild('visitor');
$new_vis_dets = $new_visitor->addChild('date', $date);
$new_vis_dets = $new_visitor->addChild('user_agent', $browser . ':' . $version);
$new_vis_dets = $new_visitor->addChild('os', $os);
$new_vis_dets = $new_visitor->addChild('ip', $ip);
$new_vis_dets = $new_visitor->addChild('visits', '0');
I also know i'm in the loop because I do get the new visitor when uncommented.
Bookmarks