Re: Example needed

From: Date: Tue, 01 Aug 2000 21:12:48 +0000
Subject: Re: Example needed
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-9557@lists.php.net to get a copy of this message
At 12:33 PM -0700 8/1/00, Chris Kovalcik wrote:
Hi, Does someone have a quick example on how to prevent multiple submits from a form? Say, a 30 sec delay until the same person can submit the same form again? Thanks, Chris
This might not work in your case, but what I have often done is this: I'm assuming you're storing form data in a database. Just create an extra 32-byte character field in your database (indexed, if possible, to make SELECTs faster), that is an md5 hash of the form data. That is: $TestField = md5(strtolower(implode('', $FormDataArray))); On occasion I've used an ereg_replace to squeeze out spaces as well -
that would make the values 'Wendell p    Snarzboggle' and 'wendell P snarzboggle' appear the same.
Before inserting the data, create the md5 hash and then see if that exists in your table: $ResultId = mysql_db_query( $YourDatabase, 'SELECT count(*) as found '. 'FROM your_table '. "WHERE TestField = '$TestField'", $LinkId); If found > 0, then there's a duplicate. One advantage of this method is that you have more control over what constitutes a duplicate - as above you can ignore case and/or embedded spaces. You could also eliminate punctuation, make data into a standard form (eg, replace 'Dr.', 'Dr ', 'doctor ' with 'Dr. '), or what have you. The disadvantage is that it requires somewhat more disk space and requires an extra SELECT (although a 'SELECT count(*)' on an indexed field should be very fast). Hope that helps - - steve edberg +--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg                           University of California, Davis |
| sbedberg@ucdavis.edu                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

« previous php.general (#9557) next »