Avoid re-submitting forms on php pages

Is there a way to avoid processing forms when updating php pages? I would like to prevent form submission when updating links to php files with the insert function in them. For example, I process a series of notes written by users at the top of each page for a new note. Besides the obvious creation of a separate php file with a header function, is there another way to do this?

+1
source share
5 answers

Use the template after redirect-receive .

  • Accept Shipment Request
  • Data processing
  • Respond to a redirect
  • Accept Get Request
  • Give an answer of 200.

If you need to display data from the submitted materials, include the line identifier or a similar line in (for example) the query string of the URL to which you redirect.

+14
source

A better way would be to make a call to header("location: form.php"); after processing the form. This will redirect you back to the form page, and if you refresh it, the browser will not re-submit the form data.

Alternatively, you can check if you have already processed the received data, but it will still give you a warning that you are going to resend the data.

You can do both, just in case someone uses the "Back" button and accidentally clicks "Send" again.

+1
source

Just check the box when you process the form for the first time so that you can check it and stop processing later. The session variable or cookie will work fine.

+1
source

You can put nonce on a page that is allowed only once so that if you see that it contains the same nonce, you do not insert this page.

+1
source

I redirect users to a new page after processing the form.

The form is a POST request for do-something.php . I am checking the input and checking if I am processing the data and redirecting to do-something.php?somethingdone . In this way, the user can press F5 without re-requesting the POST request.

+1
source

Source: https://habr.com/ru/post/1501101/


All Articles