by October 6, 2009 0 comments



Recently while upgrading our PCQuest online forums to phpBB3, we managed to
integrate reCAPTCHA. Implementing reCAPTCHA in this environment was a bit
difficult because there is no official module for reCAPTCHA available for
phpBB3. For those who don’t know what is reCAPTCHA, it’s a program used to
distinguish between a human and a bot through images that cannot be read by
computers and can only be deciphered by humans. If  your  website
receives a lot of spams, you can put reCAPTCHA on your site to make sure bots
and computer programs don’t enter your forums and blogs.

Implementing reCAPTCHA
To begin with, you have to create a pair of private and public keys which
will be needed later for authenticating your reCAPTCHA installation. For this,
you need an account at reCAPTCHA’s website http://recap tcha.net/plugins/phpbb/.
Sign up on this site and place the path for your domain in the file. Just click
on ‘Create Key’ and note down the keys which appear.

Direct Hit!

Applies To: phpBB3 Developers
USP: Implementing reCAPTCHA in phpBB3
environment
Primary Link: http://recaptcha.net /whyrecaptcha.html
Search Engine Keywords: phpbb3, recaptcha

Now modify some of the phpBB3 files so that you can integrate reCAPTCHA with
your registration page. The phpBB3 files which you will need to modify
are:template file (ucp_register.html) and configuration file (ucp_register.php).

Changes in template file Find the following old code in the ucp_register.html
file (template file) and replace it

Old code…

<!– IF S_CONFIRM_CODE –>
              <tr>

             <th
colspan="2" valign="middle">{L_CONFIRMATION}</th>
             
</tr>
              <tr>

<td class="row3" colspan="2"><span class="gensmall">{L_CONFIRM_EXPLAIN}</span></td>

             
</tr>
              <tr>

                           
<td class="row1" colspan="2" align="center">{CONFIRM_IMG}</td>
             
</tr>
              <tr>

             
<td class="row1"><b class="genmed">{L_CONFIRM_CODE}: </b><br /><span class="gensmall">{L_CONFIRM_CODE_EXPLAIN}
<!– IF S_CONFIRM_REFRESH –>{L_VC_REFRESH_EXPLAIN}<!– ENDIF –></span></td>

             
<td class="row2"><input class="post" type="text" name="confirm_code" size="8"
maxlength="8" /><!– IF S_CONFIRM_REFRESH –>&nbsp;<input type="submit" value="{L_VC_REFRESH}"
class="btnlite" /><!– ENDIF –></td>
             
</tr>
<!– ENDIF –>

New Code…

<!– IF S_CONFIRM_CODE –>
<tr><td><b class="row2"></b></td><td><b class="row2">{CONFIRM_IMG}</b></td><td></td></tr>

<!– ENDIF –>

The above code will help you in getting the reCAPTCHA image on your
registration page.

Changes in configuration file
Copy recaptchalib.php from the recaptcha download into the /includes/ucp
directory

Find this code in ucp_register.php:

}
$confirm_image = ‘<img src="’ . append_sid("{$phpbb_root_path}ucp.$phpEx",
‘mode=confirm&amp;id=’ . $confirm_id . ‘&amp;type=’ . CONFIRM_REG . $str) . ‘"
alt="" title="" />’;
$s_hidden_fields .= ‘<input type="hidden" name="confirm_id" value="’ . $confirm_id
. ‘" />’;
}

Unlike phpBB3 Captcha, reCAPTCHA does not require any extra
authentication box.

…and add this directly underneath:

include_once(‘recaptchalib.php’);
     $publickey = ‘6LcKEggAAAAAAIjIdnGkyP7xrex_DPK-UCITnft4’;
     $confirm_image = recaptcha_get_html($publickey);
 Find this code …in ucp_register.php
else
{
$error[] = $user->lang[‘CONFIRM_CODE_WRONG’};
$wrong_confirm = true;
}
}
else
{
$error[] = $user->lang[‘CONFIRM_CODE_WRONG’];
$wrong_confirm = true;
}
}
}
*/

…and then add the following code just below the previous code. This does
reCAPTCHA authentication.

         require_once(‘recaptchalib.php’);
             $privatekey = ‘6LcKEggAAAAAAEYH6L6FWP1LnZY27t5X5CTFD779’;
             $resp = recaptcha_check_answer ($privatekey,
             $_SERVER["REMOTE_ADDR"],
             $_POST["recaptcha_challenge_field"],
             $_POST["recaptcha_response_field"]);
  if (!$resp->is_valid)
{
//die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." ."(reCAPTCHA
said: " . $resp->error . ")");

$error[] = $user->lang[‘CONFIRM_CODE_WRONG’];

  wrong_confirm = true;   }

Lastly comment the following

//’confirm_code’ => array(‘string’, !$config[‘enable_confirm’],
CAPTCHA_MIN_CHARS, CAPTCHA_MAX_CHARS),

This will help you in installing reCAPTCHA easily.

To understand how reCAPTCHA works, please register with
http://forums.pcquest.com

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.

Your data will be safe!Your e-mail address will not be published. Also other data will not be shared with third person.