Re: refresh button will mail the form again.
| From: | Jason Wong | Date: | Wed, 09 Apr 2003 06:40:59 +0000 |
| Subject: | Re: refresh button will mail the form again. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143005@lists.php.net to get a copy of this message | ||
On Wednesday 09 April 2003 12:15, Tiger Girl wrote:
> I am new to PHP, currently I just built a form and mail the result to
> myself as:
> in mailform.php:
> <?php
> if ($_POST['action'] == 'submitted') {
> /* mail the form */
> } else {
> }
> ?>
>
> in form.php:
> <form action="mailform.php" method="post">
> Name: <input type="text" name="personal[name]"><br>
> Email: <input type="text" name="personal[email]"><br>
> <input type="hidden" name="action" value="submitted">
> <input type="submit" name="submit" value="submit me!">
> </form>
>
> I am using PHP 4.3.1 with Apache, it works fine, but if I use the
> refresh button on the browser, it will send the form again even I tried
> $_POST['action'] = "FALSE". Could you please tell me what I could do to
> prevent it from sending mail again? Or, just discard the form data?
The best way to prevent this from happening is:
1) Put a randomly generated token into your form in form.php
2) Store token in db
3) When form is submitted check token against ones into db if it matches
remove token from db. Process the form. If it doesn't match print a message
saying form has already been submitted.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
When the going gets weird, the weird turn pro.
-- Hunter S. Thompson
*/