Good Morning,

Hopefully there is someone around this morning that can give me a quick and easy answer.

Is there a relatively simple way to prevent a page from reprocessing data when someone hits the 'Refresh' button?

I don't want to disable the refresh, but just prevent reprocessing and creating duplicate entries into a DB table or resending of an email or any number of things that you wouldn't want to be duplicated.

I know there has to be a way to do it but for the life of me I just can't get it clear in my head, and need to get past this.

Thanks in advance for your help.
Douglas

It depends on what you have. In some cases, redirecting to a different page after the form post can prevent the issue, because they would be refreshing the page to which they were redirected.

But if you go back with the browser, then that can be circumvented as well. In that case, storing a session token can help. After you post, store a token. If you refresh and the token is set, do nothing. When you access a certain page, you can clear the token if you want.

Posting through AJAX might be an option too, because refreshing the page wouldn't trigger the event, only clicking a button would.

Thanks pritaeas, that token is the direction I was heading, but confusing myself I guess on how to use it.

It is actually a single script with 3 separate operations and when submitted it calls itself with a variable set and that variable determines which operation to perform.

When they arrive on the page the first time, the variable is not set, so it displays directions and provides a link to confirm they want to continue.

That link when clicked, sets the variable and reloads the same page which then displays their payment options and gives them a link for each that opens in a new window where they can make the payment.

Then they get the tranaction ID from the processor and come back to the same page to enter that trans ID and submit.

This sets the variable to a different value and reloads the same page to update the DB by inserting a record for the payment, and displays the success message.

At this point, if they refresh the page, it would reprocess the data

What I had thought about doing was setting that variable as a SESSION variable that could be rechecked...
But I always run into the same nagging question about how to get that session variable unset again after it is no longer needed.

Thanks again for your response. I guess I'm heading in the right direction.

Douglas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.