Bv Script Forums

Please login or register.

Login with username, password and session length
Advanced search  

News:

SMF - Just Installed!

Author Topic: ReCaptcha Installation For Bv Photo  (Read 773 times)

alan081954

  • Newbie
  • *
  • Posts: 7
ReCaptcha Installation For Bv Photo
« on: November 03, 2009, 12:53:04 AM »
I would like to see the "recaptcha"  in the register area instead of just the regular "captcha" It makes for a much more secure site so bots do not register.
« Last Edit: November 03, 2009, 05:06:53 PM by admin »
Logged

admin

  • Administrator
  • Newbie
  • *****
  • Posts: 24
    • Email
Re: ReCaptcha Installation For Bv Photo
« Reply #1 on: November 03, 2009, 05:06:25 PM »
Hi,

First of all, i want you to know that some plugins embeded in Bv Photo Beta script. This makes a bit harder to install any 3rd party plugin. To install 3rd party plugin you have to change some functions in Bv Photo.

But as you requested installation for "recaptcha" explained below. Here we go:

1. Get your "public" and "private" keys from "recaptcha" web site.

2. Download source codes for "recaptcha" to your computer and upload them in a single directory to where Bv Photo is installed.

3. Now, we have to edit 3 files of Bv Photo to install "recaptcha" plugin. These files are;
  • "/register.php"
  • "functions/register-functions.php"
  • "templates/(active_template)/register.php"

Lets start to edit them:

3.1. Editing "register.php"

3.1.1 : Find the file "register.php" in the folder where you installed Bv Photo
3.1.2 : Open the file with your favourite code editor
3.1.3 : Find the line:
Code: [Select]
$code = $_SESSION['capcode'];This line sets the session for Bv Photo Default Captcha.
What we have to do is re-setting this code to what we want. So no more session will be created by Bv Photo Default Captha. Simply we will set this session to something. Mine is "bypass". So change this line with the line below.
Code: [Select]
//$code = $_SESSION['capcode'];
$code = "bypass";

Now we have our own "$code" value instead of Bv Photo Captcha Value. So next:

3.1.3 : Find the line:
Code: [Select]
$captext = $_POST['captext'];This line defines "what user posted as security code". As we start using Recaptcha we dont need this anymore. So lets disable it. Change line with the code below.
Code: [Select]
//$captext = $_POST['captext'];
As we disabled this function we also change the line passing function. Simply change this:
Code: [Select]
registerUser($nickname, $password, $passcheck, $email, $emailcheck, $captext, $code);into this  :
Code: [Select]
registerUser($nickname, $password, $passcheck, $email, $emailcheck, $_SESSION['capcode'], $code);
Now we're all done with the file "/register.php". Here is the new "register.php" file:
Code: [Select]
<?php
/* Registration Module
##
## This page is the registration module of the application.
## Users register usernames via this page.
##
*/
require("functions/register-functions.php");

//$code = $_SESSION['capcode'];
$code "bypass";

if(isset(
$_POST['DoRegister'])) {
$nickname $_POST['username'];
$email $_POST['email'];
$emailcheck $_POST['emailcheck'];
$password $_POST['password'];
$passcheck $_POST['passcheck'];
//$captext = $_POST['captext'];
registerUser($nickname$password$passcheck$email$emailcheck$_SESSION['capcode'], $code);

}
?>


3.2. Editing "functions/register-functions.php"

3.2.1 : Change the line:
Code: [Select]
elseif(!capCheck(strtoupper($capcode), $capsess)) { $message = register_SECURITYCODESUCKS; runError($message, "outregister", "warning"); return false; }with
Code: [Select]
elseif(!capCheck($capcode, $capsess)) { $message = register_SECURITYCODESUCKS; runError($message, "outregister", "warning"); return false; }
This change will remove character uppercase which recaptcha does not need.

3.3. Editing "templates/(active_template)/register.php"

3.2.1 : Find the line below:
Code: [Select]
<td>
     <img src="<?=siteURL?>captcha.php" height="20" title="<?=CAPTCHATITLE?>" align="absmiddle" /> <input type="text" name="captext" class="border" size="6" /><br />
     <span class="notice"><?=register_ABCAPT?></span>
</td>

Change it with the code below:
Code: [Select]
<td>
     <?php
           
require_once('recaptcha_folder/recaptchalib.php'); // This will import recaptcha to register page
$publickey "6LdrMwkAAAAAAJFmU1aFKUVLrtvgeGseT4hkrJz9"// you got this from the signup page
           
$privatekey "6LdrMwkAAAAAAPV9rPL70ih9lmfFkz4FIbr9pNz3"// you got this from the singup page
           
echo recaptcha_get_html($publickey); // This line will show recaptcha

# the response from reCAPTCHA
$resp null;
# the error code from reCAPTCHA, if any
           
$error null;

if ($_POST["DoRegister"]) { // DoRegister comes from Bv Photo default registration form.
  $resp recaptcha_check_answer ($privatekey$_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);

  if ($resp->is_valid) { // This line checks if recaptcha response is valid.
     $_SESSION['capcode'] = "bypass"// So if its valid we set out session to check captcha to the setting that we've set before in register.php
  }
  else { 
     unset($_SESSION['capcode']); // Else we unset the session so session will return false
             

}
?>

<span class="notice"><?=register_ABCAPT?></span>
</td>

If you've done everything right recaptcha will work just fine. Please do not hassistate to reply this topic for problem.

Thanks.
bvscript.com
« Last Edit: November 03, 2009, 05:22:11 PM by admin »
Logged

alan081954

  • Newbie
  • *
  • Posts: 7
Re: ReCaptcha Installation For Bv Photo
« Reply #2 on: November 04, 2009, 08:10:23 PM »
Great tutorial! It worked great! Thanks for the help.
Logged