on-internet
← Community

Resetting a 2D grid state in PHP $_SESSION with PRG

Stack Overflow ·

I am building a stateful 2D grid game in PHP 8 using native sessions ($_SESSION) without a database. The script manages a turn-based board, hidden target coordinates stored in the session, attempt counters, one-time flash messages, and a reset button to start a new game. Initially, submitting a cell coordinate via POST and rendering the HTML directly caused the browser to re-submit the last move whenever the user pressed F5 (refresh). Additionally, calling session_destroy() on the reset button wiped unrelated session keys. I refactored the script to use the Post/Redirect/Get (PRG) pattern and

Comments

Sign in or sign up to comment and upvote.

No comments yet.