What are some ways to stop a form from being re-submitted if the user reloads the browser?
| SitePoint Sponsor |


What are some ways to stop a form from being re-submitted if the user reloads the browser?


after you have done the processing of the form, redirect the user away to another page using header("Location: next_page.php");
eg:
PHP Code:if(isset($_POST['submitForm'])) {
// do form processing
header("Location: nexpage.php");
exit(); // stop the script continuing just in case
}
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!


Thanks. But I am afraid that would create a "headers send" error in my case and I would have to change several things in order to avoid that.
Any other solutions?
Use a meta refresh,
echo "<meta http-equiv=\"refresh\" content=\"TIME_HERE;url=URL_HERE\">";





You can also just add a session variable when the form has been submitted successfully. Then on the same time check if the session variable is set before you resubmit the form.
Then it would not matter if the same post data is resubmit, since the session variable would be set.
Bookmarks