I'm using the following code:
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);
}
This works fine but every so often say every 3-4 weeks the hit counter will suddenly drop from say 1548 to 53 (just an example not the literal numbers) - anyone with ideas as to why this is happening?
the error log shows:
PHP Warning: fread() [<a href='function.fread'>function.fread</a>]: Length parameter must be greater than 0 in /my/home/dir/www.mysite.com/count.php on line 6