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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.