Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing resubmitting with 'Refresh'

Status
Not open for further replies.

jimoblak

Instructor
Oct 23, 2001
3,620
US
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?
 
You can use sessions.

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: TANSTAAFL!
 
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.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top