Example, session method
| code is as follows |
copy code |
|
<?p HP
if ($_post) {
if ($_session["token"]!=$_post["token"]) {
die ("illegal submission!") ");
}else{
echo "secure submission!";
}
}
$_session["token"]=md5 (rand (1,999));//form not generated once, modify value once, do not modify it before post processing, or you cannot compare to Www.111cn.net
?>
<form action= "1.php" method= "POST"
<input type= "hidden" value= "<?php echo $_session[" token "]?>" Name= "token"
<input type= "Submit" value= "commit"/>
</form> |
Example, Cookie+md5 method
| The code is as follows |
Copy Code |
|
<?php
$value = $_cookie["value"]; Read the cookie value that was last set
if (count ($_post)) {
$long = "";
while (list ($key, $value) =each ($_post)) $long. = $value;
$hash = MD5 ($long);
Setcookie ("Value", $hash, Time () +60*60);//Reset Cookies
}
if ($value!= $hash) {
Further operation of the data if the MD5 value is not the same two times
} else {
If the value of two times MD5 is the same, inform the user that the submission failed, and submit the form for duplicate
}
?> |