reCaptcha for PunBB
on another site that i’m helping to develop, i’ve integrated Carnegie Mellon University’s incredible reCaptcha script into PunBB (the forum software running on that site).
reCAPTCHA channels the effort spent solving CAPTCHAs online into correcting OCR mistakes for scanned books.
because the current release of PunBB is not plugin friendly, integrating reCaptcha isn’t a one step process, but with barely any effort it’s completely doable.
PunBB 1.2.15 was used.
Here’s how to do it:
(text version: recaptcha_and_punbb.txt)
INSTALLING reCaptcha into PunBB
1. Download the reCAPTCHA PHP Library and extract recaptchalib.php into your root PunBB directory.
3. Edit your PunBB register.php file:
Find:
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
And add these lines below it:
require_once('recaptchalib.php');
$publickey = "youpublickey";
$privatekey = "yourprivatekey";
Find:
else if (isset($_POST['form_sent']))
{
And add these lines below it:
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
Find:
Look for the block of code that begins with:
// Validate username and passwords
if (strlen($username) < 2)
message($lang_prof_reg['Username too short']);
And add these lines below that block of checks:
( below: message($lang_prof_reg[’Username BBCode’]); )
else if (!$resp->is_valid) {
message("The <b>reCAPTCHA</b> wasn't entered correctly. Go back and try it again.");
}
Find:
Near the bottom of the file, find:
<p><input type="submit" name="register" value="<?php echo $lang_register['Register'] ?>" /></p>
And add these lines ABOVE it:
<div class="inform">
<fieldset>
<legend>Are you human?</legend>
<?php echo recaptcha_get_html($publickey, $error); ?>
</fieldset>
</div>
(above the submit button!)
5. That’s it!
NOTE: copying and pasting the code from above might result in ugliness. use the text version: recaptcha_and_punbb.txt to make things easier.

September 14th, 2007 at 12:07 pm
Hiya. I am trying to get this working on my site, but I am getting an error.
Parse error: syntax error, unexpected $end in /home/path/to/register.php on line 434
Any idea on this? Any pointers would be much appreciated. Also, thank you for doing this in the first place, it is really helpful to me. This post is the only resource on the web about giving punBB reCAPTCHA functionality (that I can find, at least).
September 14th, 2007 at 1:42 pm
hi maiki,
glad you found this useful. sorry you’re having errors.
generally that error means you’re either missing a curly brace somewhere or you’re using short tags which may be a no no for your configuration.
if you want to post the block of php code around line 434 in your file, maybe it’ll be more clear.
also, if you copied and pasted code from the blog post (and not the text file), you might have pasted in smart-quotes and other nasty non-plain-text-characters that will surely cause php to get upset.
September 18th, 2007 at 1:01 am
[…] was kind enough to point me in the direction of a helpful set of instructions for integrating reCAPTCHA with punBB forums in an attempt to neutralize the forum spambots that had […]
February 27th, 2008 at 12:56 am
I was just working through how to get reCaptcha to work inside of the register.php page when I found your site. I followed the instructions and it worked the first time around. Thanks for the post.
May 22nd, 2008 at 5:42 am
Thank you!
August 14th, 2008 at 1:07 pm
Just implemented this on PunBB v1.2.19; works smashing!
Thank you!
August 17th, 2008 at 3:58 pm
Thank you!