IPB 1.3.1: reCAPTCHA on registration

Notice: If you are uncomfortable installing modifications to your board like these, I am also available to install them for you. Depending on the complexity of the modification, my prices vary. However if you’re interested, feel free to contact me for a quote. I work very quickly. :) I am also available to write custom scripts for forums such as IBP and phpBB (as well as many others).

Sick of spam bots, but don’t feel like inconveniencing your users (and not too fond of IPB’s built in CAPTCHA, for that matter)? Try using reCAPTCHA. This modification will put a reCAPTCHA field on your registration page. This modification will add a new option to your AdminCP (under Security & Privacy -> Enable Script/Bot Flood Control?), which will allow you to specify the usage of reCAPTCHA upon registration.

IPB Version: 1.3.1 Final

Difficulty: Medium

File Version: v1.0.2

Affected Files

/sources/Register.php

/sources/Admin/ad_settings.php

/Skin/*/skin_register.php

1. Register and get API Keys

  1. In order to use this modification, you must first register an account at reCAPTCHA.net
  2. Once logged in, add a new site to your account.
  3. Make sure to copy down the Public Key and Private Key that are given to you, as you will need these later.

2. Download source files

Download the latest reCAPTCHA PHP Library and extract its contents.

3. Upload recaptchalib.php

From the file you just downloaded, upload recaptchalib.php to /sources/recaptchalib.php

4. open /sources/Register.php

IMPORTANT: Make sure to replace publickey and privatekey with the API keys that you obtained during registration.

FIND:

function show_reg_form($errors = "") {

global $ibforums, $DB, $std;

* INSERT AFTER:

require_once('recaptchalib.php');

$publickey = "..."; // you got this from the reCAPTCHA site

FIND:

if ($ibforums->vars['bot_antispam'] == 'gd')

{

$this->output = str_replace( "<!--{REG.ANTISPAM}-->", $this->html->bot_antispam_gd( $regid ), $this->output );

}

else if ($ibforums->vars['bot_antispam'] == 'gif')

{

$this->output = str_replace( "<!--{REG.ANTISPAM}-->", $this->html->bot_antispam( $regid ), $this->output );

}

* INSERT AFTER:

else if ($ibforums->vars['bot_antispam'] == 'rec')

{

$this->output = str_replace( "<!--{REG.RECAPTCHA}-->", recaptcha_get_html($publickey), $this->output );

}

Now we need to validate the CAPTCHA code that gets entered upon registration.

FIND:

function create_account()

{

global $ibforums, $std, $DB, $print, $HTTP_POST_VARS;

* INSERT AFTER:

require_once('recaptchalib.php');

$privatekey = "..."; // you got this from the reCAPTCHA site

$resp = recaptcha_check_answer ($privatekey,

$_SERVER["REMOTE_ADDR"],

$_POST["recaptcha_challenge_field"],

$_POST["recaptcha_response_field"]);

FIND:

    //+--------------------------------------------

//| Check the reg_code

//+--------------------------------------------

if ($ibforums->vars['bot_antispam'])

{

if ($ibforums->input['regid'] == "")

{

$this->show_reg_form('err_reg_code');

return;

}

$DB->query("SELECT * FROM ibf_reg_antispam WHERE regid='".trim(addslashes($ibforums->input['regid']))."'");

if ( ! $row = $DB->fetch_row() )

{

$this->show_reg_form('err_reg_code');

return;

}

if ( trim( intval($ibforums->input['reg_code']) ) != $row['regcode'] )

{

$this->show_reg_form('err_reg_code');

return;

}

$DB->query("DELETE FROM ibf_reg_antispam WHERE regid='".trim(addslashes($ibforums->input['regid']))."'");

}

REPLACE WITH:

//+--------------------------------------------

//| Check the reg_code

//+--------------------------------------------

if ($ibforums->vars['bot_antispam'])

{

if ($ibforums->vars['bot_antispam'] == 'rec')

{

if (!$resp->is_valid)

{

$this->show_reg_form('err_reg_code');

return;

}

}

else

{

if ($ibforums->input['regid'] == "")

{

$this->show_reg_form('err_reg_code');

return;

}

$DB->query("SELECT * FROM ibf_reg_antispam WHERE regid='".trim(addslashes($ibforums->input['regid']))."'");

if ( ! $row = $DB->fetch_row() )

{

$this->show_reg_form('err_reg_code');

return;

}

if ( trim( intval($ibforums->input['reg_code']) ) != $row['regcode'] )

{

$this->show_reg_form('err_reg_code');

return;

}

$DB->query("DELETE FROM ibf_reg_antispam WHERE regid='".trim(addslashes($ibforums->input['regid']))."'");

}

}

5. open /sources/Admin/ad_settings.php

FIND:

$SKIN->form_dropdown( "bot_antispam",

array(

0 => array( '0'    , 'None'                  ),

1 => array( 'gd'   , 'Advanced (Requires GD Library)'    ),

2 => array( 'gif'  , 'Normal (No special requirements)'  ),

),

$INFO['bot_antispam']

)

REPLACE WITH:

$SKIN->form_dropdown( "bot_antispam",

array(

0 => array( '0'    , 'None'                  ),

1 => array( 'gd'   , 'Advanced (Requires GD Library)'    ),

2 => array( 'gif'  , 'Normal (No special requirements)'  ),

3 => array( 'rec'  , 'Use reCAPTCHA'  ),

),

$INFO['bot_antispam']

)

6. open /Skin/*/skin_register.php

FIND:

<!--{REG.ANTISPAM}-->

* INSERT AFTER:

<!--{REG.RECAPTCHA}-->

SAVE & UPLOAD

7. Enable reCAPTCHA

Installing this modification adds a new security option for you to use upon new user registration. To enable reCAPTCHA, log into your AdminCP. The option that you need to change is under System Settings -> Security & Privacy. Once there, change the option “Enable Script/Bot Flood Control?” to “Use reCAPTCHA”.

reCAPTCHA IPB Setting

Make sure to log into your AdminCP and enable the reCAPTCHA IPB setting.

Additional Notes

  1. Depending on your setup, you may have to resyncronize your skin template in order to view the new reCAPTCHA image upon registration. To do this, first log into your AdminCP. From there go to Skins & Templates -> HTML Templates -> Template Tools. Then run the tool on your selected skin in order to resynchronize it with the template in your database.

12 Responses

  1. Hyson says:

    Got it!

    Jodie, I suggest that you add one line for newbies.

    After uploading three files, log in to admin panel – skin & templates – html templates, then in the 3rd group, choose “run tool”. Then, reCAPTCHA UI will appear in the registration form.

    • Jodie says:

      I’m glad you got it to work, Hyson. :) I’d forgotten that some people may need to resynchronize their templates, so I’ll be sure to make a note of it.

  2. chap50 says:

    Génial, excellent, tout fonctionne parfaitement.
    Un grand merci ! :)

  3. Sea says:

    Thanks. ^^

  4. MichaellaS says:

    tks for the effort you put in here I appreciate it!

  5. Iris says:

    Thank you so much for all your help Jodie! :) I’m glad I got this working now, and couldn’t have done it without you! <3

  6. raf says:

    Nicely done.. bots have gotten wise to my existing captcha and I am seeing more registrations. I know recaptcha should cure it. Will try installing this later today.

  7. Hyson says:

    Jodie, would you please mod more so that it/reCPATCHA can be used in IPBv1.31’s password recovery function and email change function?

    • Jodie says:

      Yes, it is possible to do. Unfortunately due to the nature of IPB 1.3 and the fact that it’s a very outdated piece of code, I am no longer supporting the modification of it. Sorry.

  8. raf says:

    Thank you Jodie. Works like a charm!

Pings