Below are instructions on how to add ReCaptcha to the Your_Account Module In PHP-Nuke 8.0
Files you will need:
recaptchalib.php (from http://recaptcha.net/plugins/php/)
config.php (from PHP-Nuke)
index.php (from modules/Your_Account)
recaptcha_functions.php (a file I give you)
First Get Your Public and Private Keys from ReCaptcha.net, and put them in the recaptcha_functions.php file
File:recaptcha_functions.php
<?php
/**
* $Id: $
* Author: Bandit-X <www.Bandit-X.Net>
* Licence: GNU
*/
if (!defined('MODULE_FILE')) {
die ("You can't access this file directly...");
}
require_once('recaptchalib.php');
$publickey = "my public key"; // you got this from the signup page
$privatekey = "my private key";
function recaptcha_showform()
{
global $publickey;
echo "<script type=\"text/javascript\">var RecaptchaOptions = { theme : 'white'};</script>";
echo recaptcha_get_html($publickey);
}
function recaptcha_showtable()
{
global $publickey;
echo "<tr><td colspan='2'><script type=\"text/javascript\">var RecaptchaOptions = { theme : 'white'};</script>";
echo recaptcha_get_html($publickey);
echo "</td></tr>";
}
function recaptcha_check(){
global $privatekey;
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
return $resp;
}
function recaptcha_error()
{
include_once("header.php");
OpenTable();
echo "<center><font class=\"title\"><b>ReCaptcha Error!</b></font><br><br>";
echo "<font class=\"content\">The reCAPTCHA wasn't entered correctly. Go back and try it again<br>"._GOBACK."</font></center>";
CloseTable();
include_once("footer.php");
}
?>
Now lets Open up the index.php file from the Your_Account module, first make a backup of that file.
> up top. search for.
if(is_user($user)) {
include("modules/$module_name/navbar.php");
}
> below it add.
//Backwards Compatibility
if((!$_POST['gfx_check']) AND ($gfx_chk == 2 OR $gfx_chk == 3 OR $gfx_chk == 4 OR $gfx_chk == 5 OR $gfx_chk == 6 OR $gfx_chk == 7)){
if (!defined('USE_RECAPTCHA')){
define('USE_RECAPTCHA',1);//Set 1 to use ReCaptcha, Set 0 to Disable ReCaptcha
require_once('recaptcha_functions.php');
}
}
if (!defined('USE_RECAPTCHA')){
define('USE_RECAPTCHA',0);
}
===============================================================================================
in function confirmNewUser(
> search for:
if (extension_loaded("gd")
> replace with:
if ((USE_RECAPTCHA != 1) AND extension_loaded("gd")
> Search For:
."<input type=\"hidden\" name=\"random_num\" value=\"$random_num\">" ."<input type=\"hidden\" name=\"gfx_check\" value=\"$gfx_check\">" ."<input type=\"hidden\" name=\"username\" value=\"$username\">"
> replace with:
."<input type=\"hidden\" name=\"random_num\" value=\"$random_num\">";
if ((USE_RECAPTCHA == 1) AND ($gfx_chk == 3 OR $gfx_chk == 4 OR $gfx_chk == 6 OR $gfx_chk == 7)){
recaptcha_showform();
}else{
echo "<input type=\"hidden\" name=\"gfx_check\" value=\"$gfx_check\">";
}
echo "<input type=\"hidden\" name=\"username\" value=\"$username\">"
===============================================================================================
in function finishNewUser(
> search for:
if (extension_loaded("gd")
> replace with:
if ((USE_RECAPTCHA == 1) AND ($gfx_chk == 3 OR $gfx_chk == 4 OR $gfx_chk == 6 OR $gfx_chk == 7)){
$resp = recaptcha_check();
if (!$resp->is_valid){
recaptcha_error();
die();
}
}elseif ((USE_RECAPTCHA != 1) AND extension_loaded("gd")
===============================================================================================
function main(
> search for:
if (extension_loaded("gd")
> replace with:
if ((USE_RECAPTCHA == 1) AND ($gfx_chk == 2 OR $gfx_chk == 4 OR $gfx_chk == 5 OR $gfx_chk == 7)){
recaptcha_showtable();
}elseif ((USE_RECAPTCHA != 1) AND extension_loaded("gd")
===============================================================================================
function new_user(
> search for:
if (extension_loaded("gd")
> replace with:
if ((USE_RECAPTCHA != 1) AND extension_loaded("gd")
===============================================================================================
function login
> search for:
if (extension_loaded("gd")
> replace with:
if ((USE_RECAPTCHA == 1) AND ($gfx_chk == 2 OR $gfx_chk == 4 OR $gfx_chk == 5 OR $gfx_chk == 7))
{
$resp = recaptcha_check();
}
if ((USE_RECAPTCHA == 1) AND (!$resp->is_valid) AND ($gfx_chk == 2 OR $gfx_chk == 4 OR $gfx_chk == 5 OR $gfx_chk == 7)){
recaptcha_error();
die();
}elseif ((USE_RECAPTCHA != 1) AND extension_loaded("gd")
===============================================================================================
Save The File.
Upload. recaptchalib.php and recaptcha_functions.php to the same directory as mainfile.php and config.php.
Upload. index.php that you modified to the modules/Your_Account folder.
Open. config.php and set the $gfx_chk variable
# $gfx_chk: Set the graphic security code on every login screen, # You need to have GD extension installed: # 0: No check # 1: Administrators login only # 2: Users login only # 3: New users registration only # 4: Both, users login and new users registration only # 5: Administrators and users login only # 6: Administrators and new users registration only # 7: Everywhere on all login options (Admins and Users) # NOTE: If you aren't sure set this value to 0 //Example: $gfx_chk = 3;
Save And upload config.php.
Then. Check if the ReCaptcha is working.
PHP-Nuke/modules.php?name=Your_Account


