www.webdeveloper.com
Results 1 to 5 of 5

Thread: Integrating reCaptcha

  1. #1
    Join Date
    Jan 2011
    Posts
    4

    Integrating reCaptcha

    Hey guys,
    im not good at php at all, so im kinda stuck here
    im trying to get recaptcha to work with virtuemart 1.0.15
    i've tried all the tutorials and stuff but they only talk about the basic stuff like register.php and verify.php and it's different in virtuemart
    can anyone help me out with this?

  2. #2
    Join Date
    Jan 2011
    Location
    Canada
    Posts
    125
    Well I'm a rookie myself with php, but I use recaptcha on one of my sites. Don't know much of anything about virtuemart, but substitute 'register.php' with whatever your registration page is called, you must have one. Then try something like this:

    PHP Code:
     require_once('recaptchalib.php');

          
    $resp recaptcha_check_answer ($privatekey,

                                          
    $_SERVER["REMOTE_ADDR"],

                                          
    $_POST["recaptcha_challenge_field"],

                                          
    $_POST["recaptcha_response_field"]);

        if (!
    $resp->is_valid) {

            die (
    "<h3>Image Verification failed!. Go back and try again.</h3>" .

                 
    "(reCAPTCHA said: " $resp->error ")");            

          } 
    Put that on your registration page prior to any HTML. By the way "recaptchalib.php" is a file you download from the recaptcha site. It is required.
    Then, put the following somewhere in your form
    PHP Code:
    <?php 

                
    require_once('recaptchalib.php');

                
    $publickey "**************************";

                    echo 
    recaptcha_get_html($publickey);

                
    ?>
    You will need to use the private key somewhere too, but knowing nothing of your login system I can't tell you where or what to do with it.

    Hope that gives you something to go on atleast.

  3. #3
    Join Date
    Jan 2011
    Posts
    4
    thanks for the reply, this is what i got so far, i sorta changed around what u posted because of the way the code was setup, it's giving me an error, also it says that my cookies aren't enabled but they are, i never got that error before i changed the script

    Code:
    Info: Your browser does not accept cookies. To put products into your cart and purchase them you need to enable cookies.
    
    Image Verification failed!. Go back and try again.
    (reCAPTCHA said: incorrect-captcha-sol)


    PHP Code:
    <?php 
    $privatekey 
    '****************';
     require_once(
    'recaptchalib.php'); 

          
    $resp recaptcha_check_answer ($privatekey

                                          
    $_SERVER["REMOTE_ADDR"], 

                                          
    $_POST["recaptcha_challenge_field"], 

                                          
    $_POST["recaptcha_response_field"]); 

        if (!
    $resp->is_valid) { 

            die (
    "<h3>Image Verification failed!. Go back and try again.</h3>" 

                 
    "(reCAPTCHA said: " $resp->error ")");             

          } 
    if( !
    defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
    /**
    *
    * @version $Id: checkout_register_form.php 1612 2009-01-22 20:11:25Z thepisu $
    * @package VirtueMart
    * @subpackage html
    * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
    * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
    * VirtueMart is free software. This version may have been modified pursuant
    * to the GNU General Public License, and as distributed it includes or
    * is derivative of works licensed under the GNU General Public License or
    * other free or open source software licenses.
    * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
    *
    * http://virtuemart.net
    */
    mm_showMyFileName__FILE__ );
    global 
    $mosConfig_allowUserRegistration$mosConfig_useractivation;
    require_once( 
    CLASSPATH "ps_userfield.php" );
    require_once( 
    CLASSPATH "htmlTools.class.php" );

    $missing vmGet$_REQUEST"missing""" );

    if (!empty( 
    $missing )) {
        echo 
    "<script type=\"text/javascript\">alert('".$VM_LANG->_('CONTACT_FORM_NC',false)."'); </script>\n";
    }

    // If not using NO_REGISTRATION, redirect with a warning when Joomla doesn't allow user registration
    if ($mosConfig_allowUserRegistration == "0" && VM_REGISTRATION_TYPE != 'NO_REGISTRATION' ) {
        
    $msg $VM_LANG->_('USER_REGISTRATION_DISABLED');
        
    vmRedirect$sess->url'index.php?page='.HOMEPAGEtruefalse ), $msg );
        return;
    }

    if( 
    vmIsJoomla'1.5' ) ) {
        
    // Set the validation value
        
    $validate JUtility::getToken();
    } else {
        
    $validate =  function_exists'josspoofvalue' ) ? josSpoofValue(1) : vmSpoofValue(1);
    }

    $fields ps_userfield::getUserFields('registration'false''false );
    // Read-only fields on registration don't make sense.
    foreach( $fields as $field $field->readonly 0;
    $skip_fields = array();

    if ( 
    $my->id || (VM_REGISTRATION_TYPE != 'NORMAL_REGISTRATION' && VM_REGISTRATION_TYPE != 'OPTIONAL_REGISTRATION' 
                                    
    && ( $page == 'checkout.index' || $page == 'shop.registration' ) ) ) {
        
    // A listing of fields that are NOT shown
        
    $skip_fields = array( 'username''password''password2' );
        if( 
    $my->id ) {
            
    $skip_fields[] = 'email';
        }
    }

    // This is the part that prints out ALL registration fields!
    ps_userfield::listUserFields$fields$skip_fields );
    require_once(
    'recaptchalib.php'); 
    echo 
    '
    <div align="center">'
    ;

        if( !
    $mosConfig_useractivation && @VM_SHOW_REMEMBER_ME_BOX && VM_REGISTRATION_TYPE == 'NORMAL_REGISTRATION' ) {
            echo 
    '<input type="checkbox" name="remember" value="yes" id="remember_login2" checked="checked" />
            <label for="remember_login2">'
    $VM_LANG->_('REMEMBER_ME') .'</label><br /><br />';
        }
        else {
            if( 
    VM_REGISTRATION_TYPE == 'NO_REGISTRATION' ) {
                
    $rmbr '';
            } else {
                
    $rmbr 'yes';
            }
            echo 
    '<input type="hidden" name="remember" value="'.$rmbr.'" />';
        }
        echo 
    '
            <input type="submit" value="'
    $VM_LANG->_('BUTTON_SEND_REG') . '" class="button" onclick="return( submitregistration());" />
        </div>
        <input type="hidden" name="Itemid" value="'
    $sess->getShopItemid() .'" />
        <input type="hidden" name="gid" value="'
    $my->gid .'" />
        <input type="hidden" name="id" value="'
    $my->id .'" />
        <input type="hidden" name="user_id" value="'
    $my->id .'" />
        <input type="hidden" name="option" value="com_virtuemart" />
        <input type="hidden" name="' 
    $validate '" value="1" />
        <input type="hidden" name="useractivation" value="'
    $mosConfig_useractivation .'" />
        <input type="hidden" name="func" value="shopperadd" />
        <input type="hidden" name="page" value="checkout.index" />
                    $publickey = ************; 
                    echo recaptcha_get_html($publickey); 
        </form>'
    ;
    ?>
    Last edited by moemoe760; 01-21-2011 at 12:45 PM. Reason: hid the keys with *

  4. #4
    Join Date
    Jan 2011
    Posts
    4
    Having trouble finding the verify.php file (i know it'll be named something different)
    im just trying to find a palce to put this next code
    PHP Code:
     <?php
      
    require_once('recaptchalib.php');
      
    $privatekey "your_private_key";
      
    $resp recaptcha_check_answer ($privatekey,
                                    
    $_SERVER["REMOTE_ADDR"],
                                    
    $_POST["recaptcha_challenge_field"],
                                    
    $_POST["recaptcha_response_field"]);

      if (!
    $resp->is_valid) {
        
    // What happens when the CAPTCHA was entered incorrectly
        
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
             
    "(reCAPTCHA said: " $resp->error ")");
      } else {
        
    // Your code here to handle a successful verification
      
    }
      
    ?>

  5. #5
    Join Date
    Jan 2011
    Location
    Canada
    Posts
    125
    Okay, I'm using recaptcha on my registration page. What worked for me was putting this:
    PHP Code:
    <?php
      
    require_once('recaptchalib.php');
      
    $privatekey "your_private_key";
      
    $resp recaptcha_check_answer ($privatekey,
                                    
    $_SERVER["REMOTE_ADDR"],
                                    
    $_POST["recaptcha_challenge_field"],
                                    
    $_POST["recaptcha_response_field"]);

      if (!
    $resp->is_valid) {
        
    // What happens when the CAPTCHA was entered incorrectly
        
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
             
    "(reCAPTCHA said: " $resp->error ")");
      } else {
        
    // Your code here to handle a successful verification
      
    }
      
    ?>
    near the top of my registration.php page (prior to any html).

    In regards to the error you're getting, it looks like you're trying to do this with session-based logins when you aren't using session-based logins. Maybe you are, maybe you aren't, like I said I don't know virtuemart. But it seems like you're trying to refer to a cookie that hasn't been set. As far as finding "verify.php", I couldn't tell you, I'm not using anything like that. It's all on the page in question, with one exception. The "private key" is set in the include file that handles my sessions and cookies. If you can tell me more about your login system I might be able to help more.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles