Page 1 of 1

Preventing refresh

Posted: Mon Jul 30, 2007 3:57 am
by ghadacr
Hi Guys/Girls,

I need a script or a piece of code that can prevent refresh, because its making the data within the database really annoying... I tried to use the MVC model approach, but the requirements for this script differs away from that... So if any one has any code that prevents refresh of a page i will be grateful.. Thanks in advance :)

Posted: Mon Jul 30, 2007 4:32 am
by miro_igov
How it makes the database annoying? After every INSERT/UPDATE/REPLACE operation which relies on GET or POST you should redirect the user to an URL which does not contain the GET data for the database (POST is lost after redirect).

Posted: Mon Jul 30, 2007 4:42 am
by ghadacr
miro_igov wrote:How it makes the database annoying?
I tell you how it is annoying, when you got 35 entry's that are actually the same, because some idoit keeps on pressing the refresh button, because they dont think the entry has gone through....

Posted: Mon Jul 30, 2007 4:55 am
by chadhaajay
Hello, why don't you just check for the data duplication so that duplicate data records are not saved inthe database. Usually you cna use the email_address check to see if the email is already saved then prompt the user for duplicate email_address error so that if they keep on pressing refresh button again and again, it doesn't store the data in the database because it is duplicate entry.

Sincerely,

Ajay Chadha (Director)
Chadha Software Technologies

Posted: Mon Jul 30, 2007 4:56 am
by sentback
miro_igov wrote:After every INSERT/UPDATE/REPLACE operation which relies on GET or POST you should redirect the user to an URL which does not contain the GET data for the database (POST is lost after redirect).

Posted: Mon Jul 30, 2007 5:15 am
by ghadacr
Thanks for the suggestion, but the data that is being passed does not contain email address's... Also i dont want the database to handle too much of the vaildation side of things, i'm running alot of SP's....

Posted: Mon Jul 30, 2007 5:28 am
by miro_igov
Still not understand the redirection after DB query?

Posted: Mon Jul 30, 2007 6:34 am
by ghadacr
Hmm yeah i get it but, the script i got has mutiple processes running concurrently, so the redirection does sound good, but it wont solve the issue in hand.. Thanks for the suggestion though..

Posted: Mon Jul 30, 2007 8:19 am
by superdezign
ghadacr wrote:Thanks for the suggestion, but the data that is being passed does not contain email address's... Also i dont want the database to handle too much of the vaildation side of things, i'm running alot of SP's....
The database shouldn't need to do anything. You need to place restrictions on your users... All of them.

Posted: Mon Jul 30, 2007 9:29 am
by The Phoenix
ghadacr wrote:Hmm yeah i get it but, the script i got has mutiple processes running concurrently, so the redirection does sound good, but it wont solve the issue in hand.. Thanks for the suggestion though..
You don't understand.

Right now, your script upon receiving a post, processes (sends the data to the database). Instead, it should be redirecting users to a results page, then processing. That way, if they hit refresh, its refreshing the redirect - not the processing.

Its the Post->Redirect->Get pattern, and its designed specifically for the issue you are facing - even in a multiple process application.

Other alternatives (that can be defeated trivially):

- Use javascript to set the submit button onclick to unavailable/greyed out
- Use a db cache to detect whether that statement has been sent to the db in the last minute (and then don't send it)
- Use a unique key on the database so that you cannot send the same data to the db repeatedly
- Use a unique key on the processing side to prevent multiple submissions by a single user.

But all of those ignore the key issue, which is that you are processing multiple submits on refresh. The correct solution is to use the PRG pattern, as it completely changes the processing of that form to make refreshes inert.

Posted: Tue Jul 31, 2007 6:39 am
by ghadacr
Nice little article, i think i sorted the problem out last night over a strong coffee...

But thanks for the suggestion do apperciate... I might implement that in future PHP projects.... That model approach.

:)