[PHP] Several ways to prevent forms from repeating submissions

Source: Internet
Author: User

1. Use JS to make the button disabled (disable) after one click. + = prevents multiple clicks from happening and is simpler to implement.

Disadvantage: If the client prohibits JavaScript scripting, it fails.

2. Perform page redirection (redirect) after successful submission. = = Go to the Submit Success Information page.

Features: Avoid F5 repeated submissions, eliminate browser forward and backward press the same problem caused.

3. The form hides the session in the hidden field (the token generated when the form is requested). = = after receiving the form data, check whether this flag value exists, first delete, and then process the data; If it does not exist, the description has been submitted, ignoring this submission.

/*|---------------------------------| Principles & Code Examples |@ Black-eyed poet <www.chenwei.ws>|--------------------------------- *///server generates a random number to the SESSION, assigned to the form page $data[' sess_id '] = $_session[' sid ') = Mt_rand (9999), $this->load->view (' form ', $data);//The form page hidden field holds this session value <input type= "hidden" name= "Sid" Value= "<?= $sess _id;?>" >//Handle if ($_post[' SID ' = ' = ' && $_post[' sid '] = = $_session[' sid ']) {unset ($_session[' Sid ')); Echo ' processes the data ';} else{Echo ' has submitted a form ';}

4. Database Unique index constraints (the most effective way to prevent duplicate data).

---------------------------------------------------------------------------------------------

[PHP] Several ways to prevent forms from repeating 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.