when you submit a form, you may encounter a speed, such as the page suddenly load slow, the user repeatedly click the Submit button, will produce multiple data in the database, resulting in an uncontrolled situation. For example, the following situation causes the form to be repeated: Click the Submit button two times. Click the Refresh button. Use the browser Back button to repeat the previous action, causing the form to be submitted repeatedly. Repeat the form by using browser history. The browser repeats the HTTP request. The webpage was maliciously refreshed. Here are a few workarounds: one: Use the JS Settings button to turn gray $ (document). Ready (function () {$ (input:submit). Click () {setTimeout (function () { Obj.disabled=true;}, -) };}); Second: Use the session to load the submitted page, generate a random number, $code= Mt_rand (0,1000000), stored in the form's Hidden input box:< input type="Hidden"Name="Code"Value="">The PHP code on the receive page is as follows:<?Phpsession_start ();if(Isset ($_post['Code'])) { if($_post['Code'] = = $_session['Code']){ //submit the form repeatedly}Else{$_session['Code'] =$_post['Code'];//Store Code } }?>Third: The use of cookies is similar to the session, but cookies once the user's browser disables cookies, this function is invalidif(Isset ($_post['Submit']) {Setcookie ("Tempcookie","", Time () + -); Header ("Location :". $_server[php_self]); exit (); } if(Isset ($_cookie["Tempcookie"]) {Setcookie ("Tempcookie","",0); Echo"you have already submitted a form"; } Four: Use the header function to jump once the user clicks the Submit button, finishes processing the data and jumps to another pageif(Isset ($_post['Submit']) {Header ('location:success.php');//after processing the data, turn to other pages} Five: Use the database to add constraints directly in the database to add a unique constraint or create a unique index, once the user repeatedly committed, throw a warning or prompt, or only deal with the first commit data, this is the most direct and effective method, requires the pre-database design and architecture to consider the comprehensive
How php resolves and avoids duplicate submissions of form forms