PHP tips: Avoid repeated submission of forms

Source: Internet
Author: User
Have you ever encountered the title of "repeated submission? It is not difficult to solve this title. Here is a simple method to avoid repeated submission of the same form. First, we can define a session variable to retain the submission serial number of a form.

Have you ever encountered the title of "repeated submission? It is not difficult to solve this title. Here is a simple method to avoid repeated submission of the same form.

First, we can define a session variable to retain the submission serial number of a form. Here I define it as "$ userLastAction ".

Then add a hidden variable in 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
}

Avoid multiple form submissions
Submitted By: Douglas E. Cook
Date: 07/26/00
Does your database suffer from 'Duplicate post' syndrome? The cure isn't too difficult. Here is a *** 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
}

This is just a small trick to avoid repeated submission of a form. This may prevent water injection. In addition, users may submit the same form again if they do not know whether the submission is successful due to network status or other reasons.

The important principle of this technique is that it does not allow users to submit again after the rollback. that is to say, it does not allow users to submit again after the rollback. In addition, the water injection measures of Ctrl-C/Ctrl-V cannot be avoided. After all, whether it is useful or not depends on the interests of webmasters.

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.