Last active
July 4, 2018 19:44
-
-
Save marcosnakamine/873fbea46f9d2c54fa244978b0b0903a to your computer and use it in GitHub Desktop.
WordPress - Really Simple CAPTCHA plugin with custom form
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 | |
// https://br.wordpress.org/plugins/really-simple-captcha/ | |
$captcha_instance = new ReallySimpleCaptcha(); | |
$captcha_instance->bg = array( 255, 255, 255 ); | |
$word = $captcha_instance->generate_random_word(); | |
$prefix = mt_rand(); | |
$img_captcha = $captcha_instance->generate_image( $prefix, $word ); | |
if ( isset( $_POST['send'] ) && $_POST['send'] == 'ok' ) { | |
if ( $captcha_instance->check( $_POST['prefix'], $_POST['captcha'] ) ) { | |
// Congratulations you are human ! | |
} else { | |
// Sorry robot, you can not pass | |
} | |
} | |
?> | |
<form method="post"> | |
<img src="<?php echo home_url().'/wp-content/plugins/really-simple-captcha/tmp/'.$img_captcha ?>" alt=""> | |
<input type="text" name="captcha"> | |
<input type="hidden" name="prefix" value="<?php echo $prefix ?>"> | |
<input type="hidden" name="send" value="ok"> | |
<button>Send</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment