This article mainly introduces several common methods for PHP to prevent repeated submission of forms, which has good practical value in PHP project development, for more information, see the following section to describe several common methods for PHP to prevent repeated submission of forms. this is of great practical value in PHP program development. The specific method is as follows:
1. use JS to make the button disabled after one click (disable ). This method can prevent multiple clicks and is easy to implement.
The disadvantage is that JavaScript scripts are disabled on the client.
2. after the submission is successful, execute page redirection (redirect ). Go to the submitted information page.
Features: avoid repeated submission of F5 and eliminate the same problems caused by buttons forward and backward of the browser.
3. store the session in the form hiding field (the Mark generated when the form is requested ). After receiving form data, use this method to check whether the flag value exists. first, delete the value and process the data. if the value does not exist, it indicates that it has been submitted. ignore this submission.
/* // The server generates a random number and stores it in the session. the random number is allocated to the table list 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 ).
I hope the methods described in this article can help you develop PHP projects.