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.
Ooh ooh, I know this one.
Use the header function at the end of a successful insert to send the
user to a different page (e.g., header("location:
insert_complete.php");). If they reload that, all it does is re-display
the insert complete page - no duplicate entry.
I handle errors in the same file (insert.php) with a form based back
button to the form.html.
--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************