Prevent user from Back and re-submit

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
hoangvu.che
Forum Newbie
Posts: 19
Joined: Thu Mar 22, 2007 9:54 pm

Prevent user from Back and re-submit

Post by hoangvu.che »

My site flow is as follows:

+ step 1: page 1 for data input and submit
+ step 2: page 2 processes the data submitted and redirect to a result page

The problem is: At the result page, the user can press Back (resulting to page 1 again) and re-submit again.

Please help me a solution to prevent this?

Thanks a lot.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

If you're trying to create a "unique" submission system for something like voting, you're outta luck, man. Anything can be circumvented.

Depending on the level of protection you're looking for, you could:

* Set a cookie, indicating the user had already submitted the form
* Record the submission to the user's session
* Log the user's IP address
* Require the user to login with a valid email address
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Also, look into using one-time tokens.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

But if you want to clear the field values so when user clicks back the form to be empty you can use <imput type="text" value="" />
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The browser will often remember the values that were in the fields prior to submission. Setting the value attribute doesn't alter this behavior at all.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you could use some onload javascript to do it - I can think of 1 line of jQuery that would do the trick ;-)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

If you disable caching the form fields won't get repopulated.
Post Reply