$file = fopen("counter.txt",(is_file("counter.txt"))?"r+":"w+");
$count = fread($file, filesize("counter.txt"));
rewind($file);
$count +=1;
fputs($file, $count);
fclose($file);
echo "You are visitor : $count";
?>
This is the allows you have multiple page hit counter and is very easy to use.
function count_hit($filename){
$file = fopen($filename,(is_file($filename))?"r+":"w+");
$count = fread($file, filesize($filename));
rewind($file);
$count +=1;
fputs($file, $count);
fclose($file);
echo "In $filename, you are visitor #$count";
}
count_hit("counter.txt");
echo "
";
count_hit("counter.cnt");
echo "
";
count_hit("page2_counter.txt");
echo "
";
count_hit("another_page.txt");
echo "
";
?>