File counter adds 2 instead of 1
I made a simple counter, but it increments by 2 instead of 1.
$handle = fopen('progress.txt', 'r');
$pro = fgets($handle);
print $pro; // incremented by 2, WTF?
fclose($handle);
$handle = fopen('progress.txt', 'w');
fwrite($handle, $pro);
fcl开发者_StackOverflow社区ose($handle);
Everytime I read the file it has been incremented by 2, instead of 1.
Well here is the answer, based on the comment:
Be careful with front controller based on the mod_rewrite, as it act as a 404 error handler. And your browser tries to fetch favicon.ico with each request... ;)
By the way, I really love other answers. The real SO way.
$handle = fopen('progress.txt', 'r');
$pro = fgets($handle);
print $pro; // incremented by 2, WTF?
$pro++;
fclose($handle);
$handle = fopen('progress.txt', 'w');
fwrite($handle, $pro);
fclose($handle);
That seems to work for me
精彩评论