 <p>The solutions depends on the level of interaction you want that "toggle" to happen.</p> <p>If you want to achieve this toggle for every user on its own, you're good to go with sessions.</p> <p>If you want to have the toggle application-wide (every user toggles one single value) you'll have to use any kind of persistence layer (e.g. a database, a file) to store the current state of you <code>$i</code> value in it.</p>