Stop Browser from Retry

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Stop Browser from Retry

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 ;)
Post Reply