Re: capturing reloads
| From: | Curt Zirzow | Date: | Wed, 30 Jul 2003 14:58:43 +0000 |
| Subject: | Re: capturing reloads | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-157528@lists.php.net to get a copy of this message | ||
* Thus wrote Diana Castillo (diana@interhotel.com):
> anyone know how to catch if someone has reloaded a page?
The way I prevent reloads is with a combination of session
variables and an extra form field, here is how I go about it:
form_page.php:
<?
$formhash = md5(uniq(rand() . time()));
$_SESSION['formhash'] = $formhash;
// Add this to your form:
?>
<input type="hidden" name="_formhash_" value="<?php echo
$formhash?>">
process_page.php:
<?
// grab the session var and test its existance
if ( $formhash = $_SESSION['formhash']) ) {
// clear out hash in session so if the user refreshes this
// page and has a _formhash_ var it will be considered bad
unset($_SESSION['formhash']);
// test the form var against the session
if ($formhash != $_REQUEST['_formhash_']) ) {
// user did not come from the form that generated page
// so hash is invalid
}
}
} else {
// invlalid data, has no hash
}
This should be generic enough so it can be used on all form
processing pages without any modifications.
You do have to make sure that the form_page.php does not get cached
by the browser.
HTH,
Curt
--
"I used to think I was indecisive, but now I'm not so sure."