I have seen some huge discrepancies between stat trackers. Keep in mind, the google code is javascript based and thus, search engine bots will not execute that code, whereas a serverside tracker will track every ip address. Also, keep in mind that you may define "visit" differently than google. You may be tracking every page hit, for example, and they may be taking each individual remote host and looking for inactivity of say, 30 minutes, to define a visit. Also, some ISP users will have multiple ips, due to proxy servers. Here are some helpful scripts to get unique ips.
Using those same scripts here with a snippet of code from one of my old projects, I'll demonstrate a simple way to detect a search bot. I have no idea if the bot names are the same. This is old code (excluding the functions) and may need some refinement.
<?php
$is_bot = false;
$search_bots = array("msnbot","Googlebot","LocalcomBot","IRLbot","Ask Jeeves","Yahoo! Slurp","Gigabot");
foreach ($search_bots as $bot) {
if ( strpos(getip(), $bot) !== false ) {
$is_bot = true;
break;
}
}
// ... do your magic ...
function validip($ip) {
if (!empty($ip) && ip2long($ip)!=-1) {
$reserved_ips = array (
array('0.0.0.0','2.255.255.255'),
array('10.0.0.0','10.255.255.255'),
array('127.0.0.0','127.255.255.255'),
array('169.254.0.0','169.254.255.255'),
array('172.16.0.0','172.31.255.255'),
array('192.0.2.0','192.0.2.255'),
array('192.168.0.0','192.168.255.255'),
array('255.255.255.0','255.255.255.255')
);
foreach ($reserved_ips as $r) {
$min = ip2long($r[0]);
$max = ip2long($r[1]);
if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
}
return true;
} else {
return false;
}
}
function getip() {
if (validip($_SERVER["HTTP_CLIENT_IP"])) {
return $_SERVER["HTTP_CLIENT_IP"];
}
foreach (explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) {
if (validip(trim($ip))) {
return $ip;
}
}
if (validip($_SERVER["HTTP_X_FORWARDED"])) {
return $_SERVER["HTTP_X_FORWARDED"];
} elseif (validip($_SERVER["HTTP_FORWARDED_FOR"])) {
return $_SERVER["HTTP_FORWARDED_FOR"];
} elseif (validip($_SERVER["HTTP_FORWARDED"])) {
return $_SERVER["HTTP_FORWARDED"];
} elseif (validip($_SERVER["HTTP_X_FORWARDED"])) {
return $_SERVER["HTTP_X_FORWARDED"];
} else {
return $_SERVER["REMOTE_ADDR"];
}
}
?>