开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜