Reputation: 638
Here is my code http://pastebin.com/DtK8MMtU when user pressing 'Next turn' button, $_POST["turnOver"] is getting set. Then script goes into this section
if (isset($_POST["turnOver"])) {
$_SESSION["state"] = 0;
unset($_SESSION["rolls"] );
unset($_SESSION["bet"]);
unset($_SESSION["nextTurn"]);
$_SESSION["turnNumber"]++;
unset($_POST["turnOver"]);
}
By this row unset($_POST["turnOver"]);
i want this block executes only once after user pressed 'Next turn' button, but this executed every time user refreshed page (i saw this by $_SESSION["turnNumber"] value, its increasing all the time i refresh page). Also, here is $_POST var_dump from xdebug:
array (size=1)
'turnOver' => string ''... (length=9)
It means it is set?
Upvotes: 0
Views: 2002
Reputation: 22656
If the user is refreshing the page they will be sending the turnOver
POST value each time. Unsetting post will only affect the rest of that page.
Best thing to do is set a session value and set that the first time that turnOver
is sent then check against that.
Upvotes: 2
Reputation: 23500
You said
I saw this by $_SESSION["turnNumber"] value, its increasing all the time i refresh page
This is a normal beauvoir since you execute
$_SESSION["turnNumber"]++;
which will keep adding 1 at each refresh. Further more before the line
unset($_POST["turnOver"]);
Your $_POST["turnOver"]
is actually set so if you try a var_dump before the unset() command you will see it as set.
Upvotes: 2