4images Modifications / Modifikationen > Templates & Styles (Releases & Support)

[MOD] reCAPTCHA

(1/7) > >>

V@no:
This mod will replace 4images default captcha graphic with more advanced reCAPTCHA

Step 1
Register at http://recaptcha.net
Once registered, go to "My account" -> "My sites" and add each domain where you want use reCAPTCHA.
Then go to "My account" -> "My sites" and click on each domain you've added, it will show you Public Key and Private Key, write them down, you'll need them in next step.

Download PHP plugin, extract it and upload recaptchalib.php into 4images includes/ folder



Step 2
Open global.php
Find:
$captcha_filter_bg           = 1;


Insert BELOW:
$captcha_recaptcha           = 1; //0 = disable; 1 = enable with auto domain select; "yourdomain" = for one specific domain only, this domain must be specified in $recaptcha_domains below
//$captcha_recaptcha           = "yourdomain2"; //use only reCAPTCHA keys for yourdomain2

$recaptcha_domains['yourdomain1'] = array("public key for yourdomain1", "private key for yourdomain1");
/*//to add more then one domain:
$recaptcha_domains['example.com']   = array("public key for example.com", "private key for example.com");
$recaptcha_domains['4homepages.de'] = array("asdfasdfasdf", "a98sd7as9df7as");
$recaptcha_domains['google.com']    = array("23kj423h42k", "8fas9d8a9sdf9a");
*/
if ($captcha_enable && $captcha_recaptcha
    && (isset($recaptcha_domains[$captcha_recaptcha])
          || isset($recaptcha_domains[strtolower($_SERVER["HTTP_HOST"])])))
{
  $captcha_recaptcha = (isset($recaptcha_domains[$captcha_recaptcha]))
                          ? $recaptcha_domains[$captcha_recaptcha]
                          : $recaptcha_domains[strtolower($_SERVER["HTTP_HOST"])];
}
else
{
  $captcha_recaptcha = 0;
}


In the code you just inserted update $recaptcha_domains['yourdomain1'] = array("public key for yourdomain1", "private key for yourdomain1"); with the correct data, yourdomain1 replace with the domain name of your website.  public key for yourdomain1 and private key for yourdomain1 with the public and private keys from Step 1.
You can add as many domains as you wish.



Step 3
Open includes/captcha_utils.php
Find:
$captcha_enable = $captcha_enable && function_exists("imagecreatetruecolor") && function_exists("imagecopyresampled");


Replace it with:function recaptcha_image()
{
  global $captcha_recaptcha;
  if ($captcha_recaptcha)
  {
    require_once(ROOT_PATH . 'includes/recaptchalib.php');
    return recaptcha_get_html($captcha_recaptcha[0]);
  }
}
if (!$captcha_recaptcha)
{
  $captcha_enable = $captcha_enable && function_exists("imagecreatetruecolor") && function_exists("imagecopyresampled");
}




Step 3.1
Find:
  $sess_code = trim($site_sess->get_session_var('captcha'));


Insert ABOVE:
  global $captcha_recaptcha, $HTTP_POST_VARS;
  if ($captcha_recaptcha)
  {
    require_once(ROOT_PATH . 'includes/recaptchalib.php');
    $resp = recaptcha_check_answer ($captcha_recaptcha[1],
                                    $_SERVER["REMOTE_ADDR"],
                                    $HTTP_POST_VARS["recaptcha_challenge_field"],
                                    $HTTP_POST_VARS["recaptcha_response_field"]);
    
    if ($resp->is_valid)
      return true;
  }




Step 4
Open includes/page_header.php
Find:
  "url_captcha_image" => $site_sess->url(ROOT_PATH."captcha.php"),


Insert BELOW::
  "recaptcha" => ($captcha_recaptcha) ? recaptcha_image() : "",
  "recaptcha_public" => @$captcha_recaptcha[0],
  "recaptcha_private" => @$captcha_recaptcha[1],




Step 5
In templates comment_form.html, member_uploadform.html, postcard_preview.html, register_form.html and in any others where you were using captcha, use this tag:
{recaptcha}
If you wish to customize reCAPTCHA view to match your site theme or whatever, you probably will need do it via javascript (don't ask me how, I don't know), in that case you might need public or private key, for that you can use these tags:
{recaptcha_public}
{recaptcha_private}


P.S.
You can use both 4images built-in captcha and reCAPTCHA at the same time if you wish.

AntiNSA2:
works cool! POwer to the books and the blind people! Cool audio captcha.. first I was thinking... what the? but very cool.. better than entering numbers like a machiene :)

Anarchology:
Hi,

I feel stupid for asking, but I can't figure out how to incorporate the {recaptcha} into the pages. I would like to completely replace the 4Images Captcha with the reCaptcha mod. Can someone help me properly on how to substitute. I thought I added the tag in correctly, but nothing is showing up...

Original register_form.html block of code...


--- Code: ---            <td class="row2"><b>{lang_password}</b></td>
            <td class="row2"><input type="password" name="user_password" size="30" class="input" /></td>
          </tr>
          <tr>
            <td class="row1"><b>{lang_email}</b></td>
            <td class="row1"><input type="text" name="user_email" size="30" class="input" value="{user_email}" /></td>
          </tr>
{if captcha_registration}
          <tr>
            <td class="row1" valign="top"><b>{lang_captcha}</b></td>
            <td class="row1">
              <a href="javascript:new_captcha_image();"><img src="{url_captcha_image}" border="0" id="captcha_image" /></a> <br />
              <input type="text" name="captcha" size="30" value="" class="commentinput" id="captcha_input" />
              <br />
              {lang_captcha_desc}
            </td>
          </tr>
          {endif captcha_registration}
        </table>
      </td>
    </tr>
--- End code ---

V@no:
Where is {recaptcha} tag?
And make sure you did steps 1 and 2 properly.

Anarchology:
I forgot to implement the PHP Plugin from the first step. I redid the other steps, but feel like I'm improperly adding the {recaptcha} string to the files. I have been testing it on the register_form.html. Below is the full modified script from that file. As of right now, nothing is showing up.


--- Code: ---{lang_register_msg}
<form method="POST" action="{url_register}">
  <table width="100%" border="0" cellspacing="0" cellpadding="1">
    <tr>
      <td valign="top" class="head1">
        <table width="100%" border="0" cellpadding="4" cellspacing="0">
          <tr>
            <td colspan="2" valign="top" class="head1">{lang_register}</td>
          </tr>
          <tr>
            <td class="row1"><b>{lang_user_name}</b></td>
            <td class="row1"><input type="text" name="user_name" size="30" value="{user_name}" class="input" /></td>
          </tr>
          <tr>
            <td class="row2"><b>{lang_password}</b></td>
            <td class="row2"><input type="password" name="user_password" size="30" class="input" /></td>
          </tr>
          <tr>
            <td class="row1"><b>{lang_email}</b></td>
            <td class="row1"><input type="text" name="user_email" size="30" class="input" value="{user_email}" /></td>
          </tr>
{if captcha_registration}
          <tr>
            <td class="row1" valign="top"><b>{lang_captcha}</b></td>
            <td class="row1">{recaptcha}
            </td>
          </tr>
          {endif captcha_registration}
        </table>
      </td>
    </tr>
  </table>
  <input type="hidden" name="action" value="register" />
  <p align="center">
    <input type="submit" value="{lang_submit}" class="button" />
    <input type="reset" value="{lang_reset}" class="button" />
  </p>
</form>
--- End code ---

Here is the test page, since I am newly creating the complete script, I will then move it over to my site...
http://www.savegasforums.com/register.php

^^^ You can see the reCAPTCHA isn't showing up.

Thanks in advance!

Navigation

[0] Message Index

[#] Next page

Go to full version