note 59937 added to function.md5
| From: | rick dot gaither at osu1 dot php dot net | Date: | Tue, 20 Dec 2005 17:14:57 +0000 |
| Subject: | note 59937 added to function.md5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100479@lists.php.net to get a copy of this message | ||
This is a nifty function to help in securing your web-forms.
If no argument is passed the function will return an encrypted hex code representing the second it
was called. If the same hex code is passed to the function it will return the number of seconds that
have elapsed. The php script can then check the time between accessing the web-page and submitting
the POST. This thwarts script ran web-form submissions. The program can verify a suitable period has
elapsed for expected manual entries. The time check can be from 1 second to about 17 hours.
The function requires the latest PEAR Blowfish Encryption module.
This would go in the form:
<?php print "<input type='hidden' value='" . FormTimer() .
"' name='FormCode'>"; ?>
This would go in the main php (post) script:
<?php
$seconds = FormTimer($_POST['FormCode']);
if (($seconds < 10) || ($seconds > 1900)) { die "Your entry time took less than 10
seconds or more than 30 minutes"; }
?>
Function...
<?php
function FormTimer($CodeID="") {
require ('Blowfish.php');
require ('Blowfish/DefaultKey.php');
$key = "Secret^Word";
$bf = new Crypt_Blowfish($key);
$current = substr(sprintf("%d", (time()+1)),-8);
if (!$CodeID) { return bin2hex($bf->encrypt($current)); }
$len = strlen($CodeID); $cValue = -1;
for ($i=0;$i<$len;$i+=2) $Crypt.=chr(hexdec(substr($CodeID,$i,2)));
if ($Crypt) {
$time_called = $bf->decrypt($Crypt);
if ($time_called) { $cValue = (intval($current) - intval($time_called)); }
}
return $cValue;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.md5.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59937
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59937&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59937&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59937&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59937&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59937&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59937&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59937&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59937&report=yes
Search -- http://master.php.net/manage/user-notes.php