klenwell information services : DevRecaptcha

Wiki source for DevRecaptcha


Show raw source

=====ReCaptcha =====
CategoryDevelopment

ReCaptcha is a multi-platform CAPTCHA plugin that can be used to stymie or discourage spammers, bots, and other online pests. I have used it in several of my projects, including [[UserSettings | this one]], as a spam-deterrent for comment and registration forms.

====PHP Usage====
Keys are obtained from the ReCaptcha website.
%%(php)
require_once('recaptchalib.php');

$recaptcha_form_url = '/recaptcha.php';
$recaptcha_post_key = 'recaptcha_submit'; # ie, input button name
$recaptcha_private_key = 'YOUR_PRIVATE_KEY';
$recaptcha_public_key = 'YOUR_PUBLIC_KEY';

$RecaptchaResponse = NULL;
$RecaptchaError = NULL;
$recaptcha_reply = '';
$recaptcha_is_submitted = isset($_POST[$recaptcha_post_key]) ? 1 : 0;

if ( $recaptcha_is_submitted )
{
$RecaptchaResponse = recaptcha_check_answer (
$recaptcha_private_key,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"] );

if ( $RecaptchaResponse->is_valid )
{
$recaptcha_reply = '<div class="ok">recaptcha successful</div>';
}
else
{
$RecaptchaError = $RecaptchaResponse->error;
$recaptcha_reply = sprintf('<div class="fail">recaptcha error: %s</div>',
$RecaptchaError );
}
}

$recaptcha_html = recaptcha_get_html( RECAPTCHA_PUBLIC_KEY, $RecaptchaError );

$form_html = <<<XHTML
<div class="recaptcha_form">
<form action="{$recaptcha_form_url}" method="post">
{$recaptcha_html}
<input type="submit" name="{$recaptcha_post_key}" value="submit" />
</form>
</div>
XHTML;

print $form_html;
%%

====Other Examples====
[[http://code.google.com/p/cakewell/source/browse/app/controllers/demo_controller.php?spec=svnbc8ea12b48aab05dd9e29765ce2597d8bb934851&r=bc8ea12b48aab05dd9e29765ce2597d8bb934851#189 | CakePhp]]
[[http://code.google.com/p/appswell/source/browse/appspot/appswell/controllers/demo_controller.py?spec=svn7bb540a2c236b642d5794397ef4025ac4378fab1&r=7bb540a2c236b642d5794397ef4025ac4378fab1#236 | Google App Engine]] (python)

====References====
http://recaptcha.net/learnmore.html
http://en.wikipedia.org/wiki/CAPTCHA