Question

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);
    fclose($handle);

Everytime I read the file it has been incremented by 2, instead of 1.

Was it helpful?

Solution

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.

OTHER TIPS

 $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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top