I got this from http://www.phpfreaks.com/quickcode/Unique_IP_Hit_Counter/52.php
This little script is supposed to count each individual IP address in hits.txt. It looks funtional to me by looking at the code, however it does not funtion properly.
It logs my ip address properly, however it counts me multiple times for some reason. My ip is the only one logged yet the counter displays 3, and wont increment when someone in the office goes to the site. Anyone have a suggestion for correcting this?
<?php
$filename = "hits.txt" ;
if(!file_exists($filename)){
$fd = fopen ($filename , "w+");
fclose($fd);
}
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo "<p class='normalbold'>$hits\n";
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename)) ;
fclose($fd) ;
$fd = fopen ($filename , "w");
$fcounted = $fstring."\n".getenv("REMOTE_ADDR");
$fout= fwrite ($fd , $fcounted );
fclose($fd);
?>