Page 1 of 1

Stop Browser from Retry

Posted: Sat Aug 07, 2004 12:28 pm
by anjanesh
Ex:
Im having a form with a submit button.
When a user enters data and hits the submit button he is shown the data that he entered.
Now when a user clicks the refresh button it asks for retry/cancel. If he retries the data is entered again automatically by the browser. But I dont want that to happen. Once the form is sent and he refreshes the original page where the data is manually entered should appear or something. But NOT actually retry again.

Any idea how to overcome this ?
Thanks

Posted: Sat Aug 07, 2004 12:37 pm
by feyd
technically, I don't think there is a way, as that service is provided by the browser. What you can do instead, is just not insert into the database a duplicate...

Posted: Sat Aug 07, 2004 12:43 pm
by hawleyjr
Create a session variable as a flag. Before you insert the data check for the flag. If there is no flag, insert the data and create a flag.

Posted: Sat Aug 07, 2004 1:25 pm
by Bill H
To add to hawleyjr's excellent solution, though, be sure to destroy the $_SESSION flag when the user exits from the form. Otherwise if he returns to make a second submission in a legitimate manner he will not be allowed to.

Posted: Sat Aug 07, 2004 3:19 pm
by timvw
Even better solution:

Build a scriptstack in your session.
And keep track which page is allowed/expected to be requested. If it is wrong, redirect to the expected page. For example, after a submit a user redirected to the 'index' page. If he hits the back button, hits refresh next, he will be redirected to index instead of having a double entry ;)