Home  >  Article  >  Backend Development  >  How to avoid repeated submission of forms in PHP_PHP Tutorial

How to avoid repeated submission of forms in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:42:01858browse

Have you ever encountered the "duplicate submission" problem? It is not difficult to solve this problem. Here's a simple way to avoid duplicate submissions of the same form.
First, we can define a session variable to save the submission sequence 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, in processing Determine whether the form has been submitted before submitting:
if($lastAction>$userLastAction and inputIsValid(...)){
$userLastAction; // Add 1 to the serial number
// Process form data
}

Original text:
Avoid multiple form submissions
Submitted By: Douglas E. Cook
Date: 07/26/00 19:46
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 previously 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 little trick to avoid repeated submission of a form. This can prevent some flooding. In addition, sometimes due to network conditions and other reasons, users do not know whether the submission is successful and will submit the same form again.
The main principle of this technique is that the user is not allowed to resubmit after reverting, which means that modifying and resubmitting after reverting is not allowed, and the Ctrl-C/Ctrl-V irrigation method cannot be avoided. Whether it is useful or not depends on the preferences of the webmasters

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486088.htmlTechArticleHave you ever encountered the "duplicate submission" problem? It is not difficult to solve this problem. Here's a simple way to avoid duplicate submissions of the same form. First, we can define a...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn