Stop form from being resubmitted on browser reload

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:


if(isset($_POST['submitForm'])) {

// do form processing

header("Location: nexpage.php");
exit(); // stop the script continuing just in case
}

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\”>”;

Not always, if you add ob_start(); to the top of your script it will stop the errors :wink:

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.