Last active
August 29, 2015 14:01
-
-
Save p4ulypops/8d2034976534b9c0695c to your computer and use it in GitHub Desktop.
UNTESTED CODE - A simple unubtrusive captcha, that requires JS and Cookies to be enabled, as well make sure the form isn't submited before 3 seconds.
This file contains 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 | |
$expectedTimeField = md5($_SESSION['captcha_field']."_timer"); | |
if ( | |
empty($_POST[$expectedTimeField]) // Timer field doesn't exist, fake it. | |
|| !is_numeric($_POST[$expectedTimeField]) // Timer is non-numeric, JS didn't exec, fake it. | |
|| ($_SESSION['captcha_time'] + 3000) < (time() + date("Z", time()) ) // They took less than 3 seconds, fake it. | |
) { | |
// Add a rule in your inbox to look out for [!] | |
$subject = "[!] This is my subject"; | |
} else { | |
// Continue on as normal. | |
$subject = "This is my subject"; | |
} | |
?> |
This file contains 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 | |
session_start(); | |
$salt = $_SERVER['SERVER_NAME']; // or wahtever | |
$fieldName = $_SERVER['REMOTE_ADDR'].$salt; | |
$_SESSION['captcha_field'] = $fieldName; | |
?> | |
<? // The time based captcha, needs JS to run, but most REAL people will have that ?> | |
<input name="<?php echo md5($fieldName."_timer") ?>" id="<?php echo md5($fieldName."_timer") ?>" type="hidden" /> | |
<script> | |
$(document).ready(function($) { | |
setTimeout(function() { | |
var dateObj = new Date(); | |
$('#<?php echo md5($fieldName."_timer") ?>').val( dateObj.getTime() + dateObj.getTimezoneOffset() ); | |
}, 3000); // change the 3000 into a minimum of how many seconds it would take to fill out your form. | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment