Skip to content

Instantly share code, notes, and snippets.

@robtuley
Created December 30, 2014 17:46
Show Gist options
  • Select an option

  • Save robtuley/62ece5451f32a68275ad to your computer and use it in GitHub Desktop.

Select an option

Save robtuley/62ece5451f32a68275ad to your computer and use it in GitHub Desktop.
<?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.
}
@decapo01
Copy link

What goes in the [snip] sections???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment