Author Topic: [MOD] reCAPTCHA  (Read 54907 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] reCAPTCHA
« on: October 03, 2008, 03:57:30 AM »
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.
« Last Edit: July 15, 2010, 01:31:51 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline AntiNSA2

  • Hero Member
  • *****
  • Posts: 774
  • As long as I can finish my site before I die.
    • View Profile
    • http://www.thelifephotography.com
[MOD] reCAPTCHA
« Reply #1 on: March 12, 2009, 08:15:21 PM »
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 :)
As long as I can finish my site before I die.

Offline Anarchology

  • Jr. Member
  • **
  • Posts: 60
  • I LULZ too much!
    • View Profile
    • Tainted Pix
[MOD] reCAPTCHA
« Reply #2 on: April 22, 2009, 07:20:12 AM »
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: [Select]
            <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>
A personal THANK YOU to all of the great programmers on this site for helping me get my site from something basic to what it is today!

My site: http://taintedpix.com
(warning: some adult content)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] reCAPTCHA
« Reply #3 on: April 22, 2009, 09:09:25 AM »
Where is {recaptcha} tag?
And make sure you did steps 1 and 2 properly.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Anarchology

  • Jr. Member
  • **
  • Posts: 60
  • I LULZ too much!
    • View Profile
    • Tainted Pix
[MOD] reCAPTCHA
« Reply #4 on: April 22, 2009, 11:19:32 AM »
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: [Select]
{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>

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!
A personal THANK YOU to all of the great programmers on this site for helping me get my site from something basic to what it is today!

My site: http://taintedpix.com
(warning: some adult content)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] reCAPTCHA
« Reply #5 on: April 22, 2009, 03:06:28 PM »
make sure you've registered savegasforums.com at your recaptcha account (step 1) and in step 2 you added the correct public and private keys for the domain.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Anarchology

  • Jr. Member
  • **
  • Posts: 60
  • I LULZ too much!
    • View Profile
    • Tainted Pix
[MOD] reCAPTCHA
« Reply #6 on: April 23, 2009, 05:06:14 AM »
Man, is this odd! Apparently, it is something on the host server's side. If I type my site in like "http://mysite.com", the captcha shows up. BUT... if I type in my site like "http://www.mysite.com", it doesn't show. I've had this happen to me again, so I think I can fix this.
A personal THANK YOU to all of the great programmers on this site for helping me get my site from something basic to what it is today!

My site: http://taintedpix.com
(warning: some adult content)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] reCAPTCHA
« Reply #7 on: April 23, 2009, 05:48:40 AM »
no, www.mysite.com and mysite.com are two different domains. they might point to the same server, but they are different.
add both domains in you recaptcha account.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Anarchology

  • Jr. Member
  • **
  • Posts: 60
  • I LULZ too much!
    • View Profile
    • Tainted Pix
[MOD] reCAPTCHA
« Reply #8 on: April 23, 2009, 07:17:42 AM »
no, www.mysite.com and mysite.com are two different domains. they might point to the same server, but they are different.
add both domains in you recaptcha account.

Ahhh, that I didn't consider. Thank you for the tip. I'll do that.
A personal THANK YOU to all of the great programmers on this site for helping me get my site from something basic to what it is today!

My site: http://taintedpix.com
(warning: some adult content)

Offline Baz140

  • Pre-Newbie
  • Posts: 6
    • View Profile
[MOD] reCAPTCHA
« Reply #9 on: June 16, 2009, 01:18:24 AM »
Have installed recaptcha because built in captcha showing red X server side unable to correct, recaptcha works fine
 BUT I have to leave captcha turned on otherwise recaptcha shows but is bypassed regardless of correct or not,
 How can I turn off captcha to remove red x but leave recaptcha working?
http://www.suffolkbandarchives.co.uk/4images/register.php

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] reCAPTCHA
« Reply #10 on: June 16, 2009, 02:33:14 AM »
You'll need remove it manually from comment_form.html and register_form.html templates.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sebas Bonito

  • Sr. Member
  • ****
  • Posts: 271
  • Sebas Bonito
    • View Profile
[MOD] reCAPTCHA
« Reply #11 on: July 10, 2009, 01:07:10 AM »
Localisation (e.g. in german)

Just add the following part somewhere in the template (like register_form.html) above the {recaptcha}

Code: [Select]
<script>
var RecaptchaOptions = {
   lang : 'de'
};
</script>

de is (of course) the part for the localisation. So Spanish-Users should change this to es and french to fr.

Further informations here.



I've also made a tiny snippet to recaptcha an e-mail address
« Last Edit: July 10, 2009, 02:24:35 PM by Schnick und Schnack »

Offline bash-t

  • Newbie
  • *
  • Posts: 20
    • View Profile
[MOD] reCAPTCHA
« Reply #12 on: August 20, 2009, 04:51:39 PM »
Hallo! Funktioniert der Mod noch mit der aktuellen 4images Version 1.7.7 und der Lib aus der recaptcha-php-1.10.zip?

Ich habe gestern das Mod versucht auf meiner privaten Gallery zu installieren. Zuvor hatte ich das Mod Ajax Comments / Comment Rating http://www.4homepages.de/forum/index.php?topic=23866.0 installiert.

Merkwürdigerweise wurde jeder Kommentar eingetragen, auch wenn ich im Recaptcha "Hützen Grützen" eingegeben habe (was selbstverständlich nicht abgefragt wurde) ;)

Daraufhin habe ich dieses Mod für sich auf meiner öffentlichen Testgallery http://www.pawlikonline.de/temp/4images/details.php?image_id=9 installiert, und komischerweise wird dort kein Kommentar akzeptiert (auch wenn ich das Captcha löse) ;)

Hat jemand einen Tipp für mich?

Anbei noch manuellen Änderungen in der global.php. Alles andere habe ich wie beschrieben installiert.
//$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           "pawlikonline.de"//use only reCAPTCHA keys for yourdomain2

$recaptcha_domains['pawlikonline.de'] = array("6Ldq6AcAAAAAA********************""6Ldq6AcAAAAAA********************");
/*//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;
}


Hint:Selbst wenn ich die Zeile
Code: [Select]
$captcha_recaptcha           = 1; wieder einkommentiere sieht das Ergebnis gleich aus.

Viele Grüße,
Bash-T
4images Version: 1.7.7

Offline Sebas Bonito

  • Sr. Member
  • ****
  • Posts: 271
  • Sebas Bonito
    • View Profile
[MOD] reCAPTCHA
« Reply #13 on: August 20, 2009, 04:57:00 PM »
Hast Du das auch mal als "Nicht-Admin" ausprobiert? Soweit ich das in Erinnerung habe, wird bei Admins die Captcha-Funktion nicht überprüft.

Offline mawenzi

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
[MOD] reCAPTCHA
« Reply #14 on: August 20, 2009, 05:04:46 PM »
@Sebas Bonito
... richtig ... ;)

@bash-t
... willst du dir dieses gewaltige Captcha-Gerät tatsächlich in dein filigranes Template einpflanzen ...
... ich denke Captcha sollte nur eine Hilfe gegen Spam und so unscheinbar wie möglich auf der Seite sein ...
... selbst das Original 4images-Captcha ist mir zu gewaltig ... daher hier ... ;)
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...