1, submit button disabled
When the user submits, the button is immediately set to a unavailable state. This uses JS to achieve.
The pre-submission code is as follows:
$ ("#submit"). attr (' disabled ', ' true ');
$ ("#submit"). Val ("Being submitted, please wait a moment");
After execution, set the button to its original state.
The code is as follows:
$ (' #submit '). Removeattr (' disabled ');
$ ("#submit"). Val ("OK to submit");
This is only for some simple foreground submitted, if we do a form webmaster submitted to our PHP logic layer file to filter this JS.
Expiration Time Method
The user submit button becomes a token (each time the business submission token is a unique value) and sets the expiration time. When the user submits this, the detection token is consistent and expired, if consistent and does not expire, it is considered to have committed two times
Example
/*
* PHP easy to use token to prevent the form of repeated submissions
* This processing method is purely for beginners ' reference
*/
Session_Start ();
function Set_token () {
$_session[' token '] = MD5 (Microtime (true));
}
function Valid_token () {
$return = $_request[' token '] = = = $_session[' token ']? True:false;
Set_token ();
return $return;
}
Generates a token if token is empty
if (!isset ($_session[' token ')) | | $_session[' token ']== ') {
Set_token ();
}
if (isset ($_post[' test ')) {
if (!valid_token ()) {
echo "token error";
}else{
Echo ' successfully submitted, Value: '. $_post[' test ';
}
}
?>
Method Two
Open session
Session_Start ();
If there is a commit identity
if (Isset ($_get[' action ')) && $_get[' action '] = = = ' Save ') {
If there is a session and it is the same value as passed in, the submission is counted.
if (Isset ($_session[' __open_auth ')) && isset ($_post[' auth ']) && $_session[' __open_auth '] = = $_post[' Auth ']) {
Print_r ($_post);
$_session[' __open_auth ' = null;//empty
} else {
Walk up
Header ("location:post.php");
}
Exit ();
}
Authorized
$auth = $_session[' __open_auth '] = time ();
?>
Post
MySQL PHP database duplicate record prevents
$link =mysql_connect (' localhost ', ' root ', ' root '); Get a MySQL database connection
$username =$_get["name"]; Get the data from the client table only son.
$q = "SELECT * from usertable where user_name= ' $username '";
mysql_query ("SET NAMES gb2312"); Avoid Chinese garbled characters
$rs = mysql_query ($q, $link); Querying the database
$num _rows = mysql_num_rows ($RS); Total number of rows to get query results
if ($num _rows==0)
{
$exec = "INSERT into student (user_name) VALUES ($username)";
mysql_query ("SET NAMES gb2312");
mysql_query ($exec, $link); Insert data into the database without this user (registered users)
echo "User Registration successful! ";
}
Else
{
echo "The user name already exists, please re-select the user name!" ";
}
?>
The session expiration method has a very important point is a session set and commit success and unsuccessful when a session is verified, this is a bit like login if the login is successful we have to clear the session this principle is similar.