Troubleshooting of repeated forms

Source: Internet
Author: User

/**
*
* @ Authors Benjamin
* @ Date 2013-11-13 10:16:59
*/

I. FAQs about repeated submission
A> click the submit button twice.
B> Click Refresh.
C> use the browser back button to repeat the previous operation, leading to repeated form submission.
D> use the browser history to repeat the submission form.
E> repeated HTTP requests in the browser.

Ii. methods to prevent repeated submission of forms
A> disable the submit button. After the form is submitted, the current button is disabled or the click event or default event of this button is canceled. This method prevents users from clicking the button multiple times. But there is a problem. if Javascript is disabled on the client, this method will be ineffective. Of course, modern web sites should be rare.

B> Post/Redirect/Get mode. Execute page redirection after submission. This is the so-called Post-Redirect-Get (PRG) mode. In short, after a user submits a form, you can execute a client redirection and go to the successful submission information page. This avoids repeated submission by pressing F5, and does not trigger the warning of repeated submission by browser form. It also eliminates the same problem caused by pressing forward and backward by browser.

C> use cookies to process repeated forms of submission
PHP implementation:
Copy codeThe Code is as follows:
Lt ;? Php
If (isset ($ _ POST ['Go']) {
Setcookie ("tempcookie", "", time () + 30 );
Header ("Location:". $ _ SERVER [PHP_SELF]); exit ();
} If (isset ($ _ COOKIE ["tempcookie"]) {
Setcookie ("tempcookie", "", 0); echo "you have submitted a form ";
}
?>

D> store a special flag in the session. When a form page is requested, a special character flag string is generated, which exists in the session and is stored in the hidden field of the form. When accepting and processing form data, check whether the identification string exists, delete it from the session immediately, and then process the data normally. If no valid flag string is found in the Form submission, it indicates that the form has been submitted and this submission is ignored. This gives your web application more advanced XSRF protection.

E> Add constraints to the database. Add a unique constraint to the database or create a unique index to prevent duplicate data. This is the most effective way to prevent repeated data submissions.

Related Article

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.