This article introduces how to use cookies to prevent users from repeatedly submitting the same data. The principle is: if the data passes the two verification steps above, it indicates that the data is valid and valid.
This article describes how to use cookies to prevent users from repeatedly submitting the same data. The principle is: if the data passes the two verification steps above, it indicates that the data is valid and valid. at this time, we concatenate the submitted data into a string and encrypt it with MD5 to obtain an MD5 value.
Then, we put the value in the client through the Cookie. when the user submits the form next time, we repeat this step and read the MD5 value in the Cookie for comparison, if they are the same, we can conclude that the two submitted forms are the same. Otherwise, this Cookie will be replaced!
The code is as follows:
- //......
- $ Lasthash = $ HTTP_COOKIE_VARS ["lasthash"]; // read the last set Cookie value
-
- If (count ($ HTTP_POST_VARS )){
- $ Long = "";
- While (list ($ key, $ value) = each ($ HTTP_POST_VARS) $ long. = $ value;
- $ Hash = md5 ($ long );
- Setcookie ("lasthash", $ hash, time () + 60*60*24*30); // reset the cookie
- }
-
- If ($ lasthash! = $ Hash ){
- // Perform further operations on the data if the MD5 values are different twice
- }
- Else {
- // If the two MD5 values are the same, the user is notified that the submission failed.
- }
- //......
- ?>