'Strange behaviour with file_get_contents/file_put_contents [closed]

Wanted to write a quick one liner to count page loads, not worrying about users, sessions or refreshes, and tried this:

file_put_contents("page.test", ((file_get_contents("page.test"))+1));

echo "Test:".file_get_contents("page.test");

On every load or refresh, the page.test file increases by 3, not 1 which I expected. If I write each step as a separate line of code and use a counter variable as an intermediate step, then it all works as expected, but the one liner goes up 3 at a time.

Appreciate some wisdom from the experts! Thank you. Ray

php


Solution 1:[1]

I tested that code locally. and no problem with none of theme. both of theme increased one by one.

be sure you refresh the page just one time !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hamid Moladoust