Re: Clear POST variables
| From: | Richard Lynch | Date: | Thu, 16 Feb 2006 19:23:23 +0000 |
| Subject: | Re: Clear POST variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-230570@lists.php.net to get a copy of this message | ||
On Thu, February 16, 2006 9:07 am, Mike Tuller wrote:
> How do I clear out the POST variables, or the variables that I have
> set from the POST variables, so that when the page is refreshed it
> will not resubmit. I have tried unset() and have tried to set it to
> and
> empty value, but it doesn't seem to work.
You can't clear out the POST variables -- they are SENT by the browser
to you.
The simplest solution is to set up a one-time-use token and embed that
in your FORM data:
<?php
$connection = mysql_connect('localhost', 'username', 'password') or
die(mysql_error());
if (isset($_POST['example'])){
$token = $_POST['token'];
$query = "delete from token where token = '$token'";
$delete = mysql_query($query, $connection) or die(mysql_error());
if (mysql_affected($connect) === 1){
//VALID token has been presented (and already deleted)
//Process their form submission
}
else{
//INVALID token presented -- they have hit re-load
//Do whatever is appropriate / ignore, abort, error out
}
}
else{
$token = uniqid();
$query = "insert into token (token) values ('$token')";
mysql_query($query, $connection) or die(mysql_error($connection);
?>
<html><body><form action="example.php" method="post">
<input type="hidden" name="token" value="<?php echo
$token?>" />
<input type="submit" value="Go" />
</form></body></html>
<?php
}
?>
--
Like Music?
http://l-i-e.com/artists.htm