I'm wondering how to prevent a page refresh from re-posting the form values so that PHP won't re-process the same form submission twice.
For example, I'm building my own custom message board and when a poster submits their new post, they get the result page which shows that their message was successfully posted. But if they refresh the browser window, they'll end up posting the message again.
Is this where session.cache_limiter comes in?
I realize I could send another header once the post has been logged into the DB in order to forward on to yet another page (preventing this refresh scenario) but I'd prefer a slightly easier method of preventing the refresh from happening altogether.
Preventing browser refresh from reposting form values -- cac
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
if (isset($_SESSION['form_flag'])) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//process the results
//some sort of check to see if all the contents are valid
//and we are ready to process the form
if (!$form->hasErrors()) {
$_SESSION['form_flag'] = true;
}
}
}