Skip to content

Instantly share code, notes, and snippets.

@yasyf
Last active December 12, 2015 01:18
Show Gist options
  • Save yasyf/4689850 to your computer and use it in GitHub Desktop.
Save yasyf/4689850 to your computer and use it in GitHub Desktop.
Simple Math Spam Check
<?php
$one = rand(1,10); $two = rand(1,10);
define('_def_check_spam', "$one + $two =");
?>
<input type="text" name="contact-spam-check" id="contact-spam-check" value="<?php echo _def_check_spam; ?>" onfocus="clearInput(this,'focus','<?php echo _def_check_spam; ?>')" onblur="clearInput(this,'blur','<?php echo _def_check_spam; ?>')" />
<input type="hidden" name="contact-spam-answer" id="contact-spam-answer" value="<?php echo $one+$two; ?>" />
<?php
if($_REQUEST['contact-spam-check'] !== $_REQUEST['contact-spam-answer'])
{
$response['error']=1;
$response['info'][]=array('fieldId'=>'contact-spam-check','message'=>"Hint: ".$values['spam-answer']);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment