ReCaptcha
CategoryDevelopmentReCaptcha 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 this one, as a spam-deterrent for comment and registration forms.
PHP Usage
Keys are obtained from the ReCaptcha website.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;
$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
CakePhpGoogle App Engine (python)
References
http://recaptcha.net/learnmore.htmlhttp://en.wikipedia.org/wiki/CAPTCHA
[There are no comments on this page]