[PHP] several methods to prevent repeated submission of forms

Source: Internet
Author: User
Tip 1. Use JS to make the button disabled once (disable ). It is easy to implement multiple clicks. Disadvantage: it is invalid if the client disables JavaScript scripts. 2. After the submission is successful

Tip 1. Use JS to make the button disabled once (disable ). = Prevent multiple clicks, which is easy to implement. Disadvantage: it is invalid if the client disables JavaScript scripts. 2. After the submission is successful

Bytes ---------------------------------------------------------------------------------------------------

1. Use JS to make the button disabled after one click (disable ). => To prevent multiple clicks, the implementation method is simple.

Disadvantage: it is invalid if the client disables JavaScript scripts.

2. After the submission is successful, execute page redirection (redirect ). => Go to the successful submission page.

Features: avoid repeated submission of F5 and eliminate the same problem caused by browser forward and backward pressing.

3. Store the session in the form hiding field (the mark generated when the form is requested ). => After receiving the form data, check whether the flag value exists. Delete the value first and process the data. If the value does not exist, it indicates that it has been submitted. Ignore this submission.

/* | ------------------------------- | Principle and sample code | @
 
  
| --------------------------------- * // The server generates a random number and saves it to the session, distribute to table single page $ data ['sess _ id'] = $ _ SESSION ['sid '] = mt_rand (1000,999 9 ); $ this-> load-> view ('form', $ data); // hide the field on a single table page to store this session Value
  // Process if ($ _ POST ['sid ']! = ''& $ _ POST ['sid '] = $ _ SESSION ['sid']) {unset ($ _ SESSION ['sid ']); echo 'process data';} else {echo 'submitted form ';}
 

4. unique database index constraints (the most effective way to prevent duplicate data ).

Link: http://www.cnblogs.com/farwish/p/3911588.html

@ Blackeye poet

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.