Skip to content

Instantly share code, notes, and snippets.

@mcbrwr
Last active August 29, 2015 13:57
Show Gist options
  • Save mcbrwr/9767784 to your computer and use it in GitHub Desktop.
Save mcbrwr/9767784 to your computer and use it in GitHub Desktop.
form spam protection - the easy way
$('form :text').keydown(function(){
if (!$(this).parents('form').children('.pl').length) {
var d = new Date();
var n = d.getDay()*d.getDate();
$(this).parents('form').append('<input type="hidden" name="pl" class="pl" value="'+n+'">');
}
});
<?php
if ( $_POST && isset($_POST['pl'] && $_POST['pl']== date('w')*date('j') ) ) {
// treat form
} else {
die('you just died. insert coin to continue');
}
@mcbrwr
Copy link
Author

mcbrwr commented Mar 25, 2014

BIG disadvantage (i admit) is that without JS sending of the form is not possible. I was thinking of combing his with a php hidden field that's inserted if a valid referrer page is found.

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