This is a simple hit counting function that:
1.) Looks for a file named count.txt
2.) Upon finding the file this function either adds the numeric value of 1 to the beginning of the file or adds 1 to the current value within the file.
Enjoy - JR
<?php
function hitCount()
{
if(file_exists('count.txt'))
{
$file = fopen('count.txt', 'r');
$data = fread($file, filesize('count.txt'));
fclose($file);
$file = fopen('count.txt', 'w');
fwrite($file, $data+1);
return $data+1;
}
else
{
$file = fopen('count.txt', w);
fwrite($file,1);
fclose($file);
return 1;
}
}
?>
If you're getting permission
If you're getting permission errors don't forget to chmod 777 the path to the directory to the script. Also don't forget to create the count.txt file and chmod 777 it as well.
JR Chew
Founder & CEO
Creative (ctrl)