Repeated submission is a problem we often encounter in development, in addition to using JS to prevent the recurrence of forms, but also can use PHP to prevent duplicate submissions Oh.
<?php
/* * PHP How to prevent the form of duplicate
submission
/session_start ();
if (Empty ($_session[' IP ')) {//First write operation to determine whether the IP address is logged, to know whether to write to the database
$_session[' ip ' = $_server[' remote_addr ']; First write, a foreshadowing of the back refresh or back
//...........//write the database operation
} else {//already has the first write operation, and then no longer write to the database
echo ' Please do not refresh and rewind again '; Write some hints or other things that have been written
}
?>
Specific principles
Session range variable token to prevent.
1. Open session:
session_start ();
2. If a form is submitted
Token is included in the form as a hidden.
<input type= "hidden" name= "token" value= "<?php echo $token;?>"/>
3. If you are submitting a form repeatedly
if ($_session["token"]!= $token) {
//Do not allow duplicate submissions in this processing
//Header ("Location:". $_server[' php_self ']);
} else {
//normal form submission, here processing
//echo "submitted";
}
4. Set token value
$token = Mt_rand (0,1000000);
2$_session[' token ' = $token;
The above is about how to solve the PHP form to repeat the implementation method of submission, I hope to help you learn.