Jump to content

Best way to prevent refresh rerunning php code in script


jwhite68

Recommended Posts

I have a fairly simple PHP page, which takes form input for a message, and on pressing the send button, it sends an email out.

 

The problem I have is that when a user presses refresh, it sends the email out again.

 

I use a form action to send a hardcoded value of sent=1, which reruns the script in order to send the email out.  So when pressing refresh, it still has this value of 1 set, and hence the issue.

 

Does anyone have any advice on how best to deal with refresh, so its not processing the form again?

The simplest method I can think of is to set a session variable.  If you're not familiar with sessions, it's time to learn :)  They are very useful things.  If you set the session variable when the form is first submitted, then you can test it the second time and recognize that something is awry.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.