Re: Clear POST variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux