View Single Post
  #10 (permalink)  
Old 01-18-2008, 03:53 AM
MarekSpace MarekSpace is offline
Pligg Donor
 
Join Date: Jan 2008
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Code for Register User reCaptcha use

Quote:
Originally Posted by MarekSpace View Post
So I see why you would want reCaptcha for adding new stories but what about the first step which is when they register? Wouldn't that alleviate the problem of spam bots creating accounts?
This works for me.

1) In register_center.tpl add this:

{if isset($form_captcha_error)}{ foreach value=error from=$form_captcha_error }<br /><span class="error">{$error}</span><br />{ /foreach }<br />{/if}

{php}
require_once('recaptchalib.php');
$publickey = "..."; // you got this from the signup page
echo recaptcha_get_html($publickey);
{/php}

BEFORE THIS

<input type="submit" name="submit" value="{#PLIGG_Visual_Register_Create_User#}" class="log2" tabindex="36" />

2) In register.php add this:

require_once('recaptchalib.php');
$privatekey = "...";

$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) { // if both captchas don't match
$error = true;
}


BEFORE THIS

$vars = array('username' => $username);
check_actions('register_check_errors', $vars);

AND THIS

$main_smarty->assign('form_captcha_error', 'The reCAPTCHA code you entered was incorrect.');

AFTER THIS

$main_smarty->assign('form_password_error', $form_password_error);
The Following User Says Thank You to MarekSpace For This Useful Post: