PHP how to avoid repeated submission of forms. Have you ever encountered the problem of "repeated submission? It is not difficult to solve this problem. Here is a simple method to avoid repeated submission of the same form. First, we can define whether you have encountered the "repeated submission" problem? It is not difficult to solve this problem. Here is a simple method to avoid repeated submission of the same form.
First, we can define a session variable to save the submission serial number of a form. Here I define it as "$ userLastAction ". Then add a hidden variable to the form and set the value to $ userLastAction 1:
>
Finally, determine whether the form has been submitted before processing and submission:
If ($ lastAction> $ userLastAction and inputIsValid (...)){
$ UserLastAction; // add 1 to the serial number
// Process form data
}
Original article:
Avoid multiple form submissions
Submitted By: Douglas E. Cook
Date: 07/26/00
Does your database suffer from "duplicate post" syndrome? The cure isnt too difficult. Here is a simple way to prevent users from submitting the same form multiple times.
First, declare a session variable to store a serial number for each form. I call mine "$ userLastAction. "Then, in every form where duplicate submission is a problem, include a hidden field, and set the value to $ userLastAction 1:
>
Finally, verify that the form has not been previusly submitted before acting on the submission:
If ($ lastAction> $ userLastAction and inputIsValid (...)){
$ UserLastAction; // Increment serial number
// Act on form here
}
Translated from: phpbuilder
This is just a small trick to avoid repeated submission of a form. In this way, the user may not know whether the submission is successful due to network conditions or other reasons. In addition, the user may submit the same form again.
The main principle of this technique is that the user is not allowed to submit again after rollback, that is to say, it is not allowed to modify and submit after rollback, and the irrigation method of Ctrl-C/Ctrl-V cannot be avoided. Whether it is useful or not, depending on the webmaster's preferences
Why? It is not difficult to solve this problem. Here is a simple method to avoid repeated submission of the same form. First, we can define...