"Corey Mosher" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
> I have a site that performs insertions into a database, then
> uses header to redirect the user to a certain page. If the
> user hits the back button, then the submit button again, the
> information will be inserted twice. How can I prevent this?
>
> Thanks
>
> Corey Mosher
There are many ways to prevent this, these are what I do.
Use PHP4 session and my form class to prevent this. I form inputs to something
like $HTTP_SESSION_VARS['FORM_VAR'].
1) When form is displayed at first time, I set session var
"form_is_not_submitted = true" and "unset($HTTP_SESSION_VARS['FORM_VARS'])"
2) When user submits form, display confirm screen. If there is validation error,
displays error.
3) If user submit (decide to store data), check "form_is_not_submitted", get
data form session, store to database, and unset form data.
Note: With this, user must start over to send data to server again at least.
Works both session cookie and URL.
OR
Use MD5 to check is data is changed or not.
1) On browser, compute md5 sum using JavaScript when submit form.
2) On server, get record (stores md5 sum computed on server) compare the md5 sum
sent form client. If it is differ, save data into database.
Note: This method is more reliable than next on,.but requires JavaScript.
OR
Use cookie to see if user is submitted.
1) When form is displayed, send cookie like [form_is_not_submitted = true]
2) When form is submitted, set the cookie to false.
3) Check cookie value before inserting data into database.
Note: This is not reliable method, unless you detect cookie is enabled or not,
though. And requires cookie of course.
I don't do this but if you do not want to use Cookie and JavaScript, how about
compare fields data for one by one?
(or you can use URL session with the 1st method)
I think there are many other ways to do the same thing. Anyone?
--
Yasuo Ohgaki
>
> -----------------------------
> Hub.Org Networking Services
> 251 Main St.
> Wolfville, NS
> Canada
> B0P 1X0
> Email: [EMAIL PROTECTED]
> Phone: (902) 542-3657
> -----------------------------
> PostgreSQL, Inc.
> 251 Main St.
> Wolfville, NS
> Canada
> B0P 1X0
> Email: [EMAIL PROTECTED]
> Phone: (902) 542-0713
> -----------------------------
> Fax: (902) 542-5386
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]