Php forms can be submitted repeatedly. To solve the php form repeated submission implementation method, repeated submission of php forms is a common problem during development. apart from using js to prevent repeated submission of forms, at the same time, it solves the php form repeated submission implementation method, and php form repeated submission
Repeated submission is a common problem during development. in addition to using js to prevent repeated submission of forms, php can also be used to prevent repeated submission.
<? Php/** php: how to prevent repeated forms */session_start (); if (empty ($ _ SESSION ['IP']) {// The first write operation, determine whether an ip address is recorded to know whether to write data to the database $ _ SESSION ['IP'] = $ _ SERVER ['remote _ ADDR ']; // The first write operation, pave the way for refresh or backend judgment //........... // database write operation} else {// the operation after the first write is performed, and the echo will not be written into the database. 'Please do not refresh or rewind '; // write some written prompts or other things}?>
Principle
The token of the session range variable is prevented.
1. enable session:
Session_start ();
2. if a form is submitted
if (isset($token))
The token is included in the form of hidden.
3. if the form is submitted repeatedly
If ($ _ SESSION ["token"]! = $ Token) {// do not allow repeated submission. process it here // header ("location :". $ _ SERVER ['php _ SELF ']);} else {// normal form submission, which is processed here // echo "submitted ";}
4. set the token value
$ Token = mt_rand );
2 $ _ SESSION ['token'] = $ token;
The above is about how to solve the php form repeated submission implementation method, hope to help you learn.
Repeated commit is a common problem during development. besides using js to prevent repeated submission of forms...