I have a form submission page that triggers another page to do some database queries. Is there some trick to prevent the second action page from doing it's thing again if the second page is refreshed?
In the script that produces the submission form, set a session variable called "data" with a value of "set".
Your script that accepts the submitted data can then check for the existence of the variable "data", and that it's value is "set".
If the variable exists and has the value "set", the database manipulating script then runs. Once it's run, it can set the value to "inserted".
If the variable doesn't exist, or has the value of "inserted", then your second script can barf. Want the best answers? Ask the best questions:
Depending on what the second page does... I like to redirect them off of it right away
header("location: blahblah"
The back button can still do funky things though, so if malicious users are your concern, it's not a good way about things.
Now, that said, off the top of my head, you could register a session variable on the submission of the first page, set it equal to 1, then on the second page, if it's set equal to 1, set it to 2 and process, if it's set to 2 tell them action already taken, go away? Would this circumvent the problem or are session variables also reset on reload and back clicks?
Easy enough to test, maybe I'll look into this when I get home tonight, or if someone else has some info.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.