Preventing back button press and resubmitting
Moderator: General Moderators
Preventing back button press and resubmitting
Hi i am making a form which has name and code (captcha image) as fields to be entered. I have given a timeout of x so if the form is submitted after x secs then it will print timeout and also used a token verification..
The problem
If the user submits a data then processing is fine. But when he presses the back button of browser and submit again then the captcha image remains same. [but changes when the form is refreshed] So the user in this case submits the form presses back and then submits the form and floods my database with same data again and again. Is there a way so that when user presses back button then the captcha image refreshes. Or some other simple solution?
The problem
If the user submits a data then processing is fine. But when he presses the back button of browser and submit again then the captcha image remains same. [but changes when the form is refreshed] So the user in this case submits the form presses back and then submits the form and floods my database with same data again and again. Is there a way so that when user presses back button then the captcha image refreshes. Or some other simple solution?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
How to redirect
I understand that. Now i will have 3 pagesCoderGoblin wrote:The redirect actually replaces the the page url in the history. Effectly the original page does not exist so you cannot "back" to it.
1> form page
2> processing
3> another page for url refreshing of browser
My doubt is to how to redirect from the processing page as i don't have any input field in that processing page so i cant post to refresh.php (say the 3rd page) .
How do i redirect to that refreshing page after processing?
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
The form and form processing are normally done on the same page /within the same php script...
Makes processing and maintenance easier than having 1 form and one processing page. Consider that this way you know what errors there are and can adjust the form accordingly.
There is nothing stopping you from redirecting to the same page. All that will happen is that the $_POST array will be empty.
Code: Select all
<?php
if (!empty($_POST['checkform'])) { // or whatever
// Validate entries and set something like $valid=1 or an error message
if ($valid) {
header('Location: http://mysite.com/nextpage.php');
exit;
}
}
// Get what you need for output
// Output including form unless you have it below the end of the php block.
?>There is nothing stopping you from redirecting to the same page. All that will happen is that the $_POST array will be empty.
Code: Select all
if(! $fault){
echo "received the content";
header('Location: http://ieeevit.org/form/index.php');
exit;
}The above code gives only the echo part and no redirect
and if i echo after redirect then the message is not shown but directly redirected. Any solution ?
-
GloriousEremite
- Forum Newbie
- Posts: 13
- Joined: Tue Aug 14, 2007 1:00 pm
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact: