Created
December 30, 2014 17:46
-
-
Save robtuley/62ece5451f32a68275ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $salt = 'MySecretSalt'; | |
| // ... [snip] ... | |
| // output hidden form fields | |
| foreach ($captcha['answers'] as $checksum) { | |
| $salted = md5($checksum.$salt); | |
| echo '<input type="hidden" name="ans[]" value="'.$salted.'" />'; | |
| } | |
| // ... [snip] ... | |
| // on submission, validate against hidden fields | |
| $ans = $_POST['captcha']; // .. or whatever! | |
| $checksum = md5(strtolower(trim($ans))); | |
| $salted = md5($checksum.$salt); | |
| if (in_array($salted,$_POST['ans'])) { | |
| // passed..! | |
| } else { | |
| // error: redisplay form, etc. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What goes in the
[snip]sections???