Set USE_FLOCK to false.');
}
}
else
{
// No, we're not using file locking
if ($mode == 'r')
{
return @fread($fp, filesize($file));
}
@fwrite($fp, $data);
}
@fclose($fp);
}
// ######################## Start Main Script #########################
if (!check_exists_writable(COUNT_FILE))
{
die('Error: ' . COUNT_FILE . ' does not exist or is not writeable.');
}
else if (!check_exists_writable(IP_FILE))
{
die('Error: ' . IP_FILE . ' does not exist or is not writeable.');
}
else
{
// Get current count
$count = fp(COUNT_FILE, 'r', '', USE_FLOCK);
// Do we only want to count 'unique' visitors?
if (ONLY_UNIQUE)
{
// Get visitor ip and check against our ip log
$ip = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$ips = fp(IP_FILE, 'r', '', USE_FLOCK);
$ips = explode("\n", $ips);
$visited = (in_array($ip, $ips)) ? true : false;
// They've not visited before
if (!$visited)
{
fp(IP_FILE, 'a', $ip . "\n", USE_FLOCK);
fp(COUNT_FILE, 'w', $count + 1, USE_FLOCK);
}
// Memory saving
unset($ips);
}
else
{
// No, we wish to count all visitors
fp(COUNT_FILE, 'w', $count + 1, USE_FLOCK);
}
// Do we want to display the # visitors as graphics?
if (USE_IMAGES)
{
$len = strlen($count);
$display = '';
for($i = 0; $i < $len; $i++)
{
$count = substr($count, $i, 1);
$display .= '
';
}
echo $display;
}
else
{
// Nope, let's just show it as plain text
echo '' . $count . '';
}
}
// EoF
?>