Preventing refresh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Preventing refresh

Post 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 :)
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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).
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post 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....
chadhaajay
Forum Newbie
Posts: 2
Joined: Sat Jul 28, 2007 4:45 am

Post 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
sentback
Forum Newbie
Posts: 24
Joined: Fri May 04, 2007 9:46 am

Post 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).
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post 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....
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Still not understand the redirection after DB query?
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post 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..
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
User avatar
The Phoenix
Forum Contributor
Posts: 294
Joined: Fri Oct 06, 2006 8:12 pm

Post 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.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post 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.

:)
Post Reply