Chapter introduces how to use cookies to prevent users from submitting the same data repeatedly. The principle is: if the data has passed the above two authentication, it indicates that the data is legitimate and valid. At this time, we string the submitted data into a string and obtain an MD5 value after using MD5 encryption.

Then we put this value into the client through the Cookie. When the user submits the form next time, we will re-operate this step and read the MD5 value in the Cookie for comparison. If it is the same, we can conclude that the form submitted twice by the user is the same.

The code is as follows:

  • / /…
  • $lasthash = $HTTP_COOKIE_VARS[“lasthash”]; // Reads the Cookie value set last time
  • 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) {
  • // If two MD5 values are different, perform further operations on the data
  • }
  • else {
  • // If the two MD5 values are the same, the user is informed that the submission failed
  • }
  • / /…
  • ? >