PHP how to avoid repeated submission of forms _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.