I'm using the following basic PHP:
<?php
if (file_exists('count_file.txt'))
{
$fil = fopen('count_file.txt', r);
$dat = fread($fil, filesize('count_file.txt'));
echo $dat+1;
fclose($fil);
$fil = fopen('count_file.txt', w);
fwrite($fil, $dat+1);
}
else
{
$fil = fopen('count_file.txt', w);
fwrite($fil, 1);
echo '1';
fclose($fil);
}
?>
as a hit counter (I'd rather not have one but it's been insisted we do). The txt file keeps count of the hits and it works...however the counter randomly (sometimes after a few weeks, sometimes months later) decides to trip up and drops from say 4300 to 11. Can anyone tell me how to rectify this as it is becoming annoying??