Re: How to handle user hitting the browser refresh
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: How to handle user hitting the browser refresh

From: Bob Smith <bobsmith1@marketweighton.com>
Date: Sat Jul 16 2005 - 11:49:13 CEST

Mark Feller wrote:

> What are best practices to check to see if a .php script is called for the
> first time versus a user hitting a refresh button on their browser?
>
> I am playing around with a PHP front-end to a database. If the user
> enters values in a form (form.html), hits submit, the PHP script
> (insert.php) puts
> the submitted fields into the database as intended. insert.php displays a
> success message if successful or an error message otherwise. If the user
> hits the brower refresh button while at insert.php, the data is
> re-entered, and I end up with a duplicate entry in the database.
>
> This is the default behavior of Opera. IE prompts if I want to resend the
> data vs. not doing anything. If the data is resent, then the duplicate
> entry happens. I need to guard against this either way.
>
> Thanks for your help.
as Chuck mentioned redirect the user after successful submission to the
database. ( perhaps the db action should not be in a page delivered to the
user, but a separate script, you can set the script to run in the action
attribute of the form element )
G

-- 
http://www.kolumbus.fi/bob.smith
Received on Mon Oct 17 21:08:29 2005