PHP prevents form recurrence Two implementation methods _php instance

Source: Internet
Author: User

PHP prevents forms from being submitted repeatedly

Due to the network reason, often came out to point the Submit button, the Web page did not respond, and then click again. This will result in the background received two submissions, so that two times processing, this article to introduce you to prevent the form of repeated submission of several methods

1. Front End Solution

Method One:

Can be solved by the front end. When the user points to the submit button, the first use of JS for effective judgment, no problem, the submit button "disabled" off. and then submit!

Method Two:

Use Ajax to submit the form. When the Submit button is clicked, disable the push button, or set a status value of 1 to indicate that it is being committed. When the submission is made, the judgment is not processed if it is being submitted. Wait until the Ajax returns, and then restore the status.

2. Back-end Solution

Sometimes the front end can not completely solve the problem, such as I used jquery.validateengine, there is no way to set the state. So consider the back end solution.

if (Session ("Act_last_time")!= ') {
 if (floor (Time ()-(int) session ("Act_last_time")% 86400/60) <1) {
  $ This->error ("Sorry, not frequent submissions within a minute!") ", U (' Wap/myact/list '), 5);
 }
} else{
 $t = (int) time ();
 echo $t;
 $_session ("Act_last_time", $t);
}

The back end solution is not very friendly, but absolutely effective. That is, the submission frequency is controlled. I set it here for 1 minutes.

Thank you for reading, I hope to help you, thank you for your support for this site!

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.