View Single Post
  #52  
Old 5th August 2018, 19:22
outtyrox outtyrox is offline
Senior Member
 
Join Date: Apr 2015
Posts: 59
Default
Quote:
Originally Posted by joeroberts View Post
problem here is
Code:
$response = $_POST["g-recaptcha-response"];
becuase you well not get that $_POST
you well need to use the
Code:
$recaptcha_response_field
correct because not part the form so the js has to do it from my understanding which it does but somewhere there's still an issue I cannot resolve.

I've added the following to debug it but I'm not understanding the issue yet.

//echo "<pre>";
//print_r($_POST);

and

//testing to see if response working. comment out once working
echo "<pre>";
print_r($response);



I thought I just use the $recaptcha_response_field for the response varible but even that doesn't produce a success for the response


here's what i see from the class_captcha.php response



//echo "<pre>";
//print_r($_POST);
Click the image to open in full size.



CAPTCHA success failing
Click the image to open in full size.


//testing to see if response working. comment out once working
echo "<pre>";
print_r($response);
Click the image to open in full size.

Bump: I have fixed this and here's how.

the _POST of the variables to the response was not being assigned for some reason when calling ajax/signup.php at sigup and running the library/class_captcha.php

I simply made a variable in ajax/signup.php to assign the response to and that got ride the response not assigned error


edited working class_captcha.php

Code:
<?php 

class TSUE_captcha
{
    public function verifyCaptcha($recaptcha_challenge_field, $recaptcha_response_field)
    {
                
                //
                //PUT YOUR PRIVATE KEY HERE//
                $secret = "6LcsM2gUAAAAAAjbvuAs-YtADTLyAKkG96AX8nmK";
                //
                //
                //
                global $_POST;
                $remoteip = $_SERVER["REMOTE_ADDR"];
                $url = "https://www.google.com/recaptcha/api/siteverify";
         
                // Curl Request
                $curl = curl_init();
                curl_setopt($curl, CURLOPT_URL, $url);
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, array(
                    'secret' => $secret,
                    'response' => $recaptcha_response_field,
                    'remoteip' => $remoteip
                    ));
                $result = curl_exec($curl);
                curl_close($curl);
         
                $result = json_decode($result);
                
                
                //echo "<pre>";
                //echo print_r($recaptcha_response_field);
                //echo print_r($result);
                //echo "<pre>";
                
                
                if ($result -> success) {
                    return true;
                }
                else
                {
                    return false;
                }
    }

}
?>


edited ajax/signup.php


- search for $_POST["g-recaptcha-response"]; in ajax/signup.php
- created a variable $recaptcha_response_field = $_POST["g-recaptcha-response"];
- edit if( !$verifyCaptcha->verifyCaptcha($recaptcha_challenge_field, $_POST["g-recaptcha-response"];))

and make it

- if( !$verifyCaptcha->verifyCaptcha($recaptcha_challenge_field, $recaptcha_response_field))


Click the image to open in full size.

Bump: Here's the updated TSUE v2.2 source code with Recaptcha v2 working

- Complete with files updated included that joe made with one minor edit to /ajax/signup.php
- Updated default database with template edits already done so you dont have to do them. only the public key entry in captcha template

1. Extract and upload directory to your domain web host
2. Create a database in CPANEL
3. Use MyPHPAdmin and Import default database file to your newly created database
4. Run installer: https://yourdomainnamehere.com/tsue_install/install.php

5. Make a Google Recaptcha key pair for your domain

- Edit template named captcha and put in your and public captcha key
- Edit /library/classes/class_captcha.php and put in your private captcha key

6. Proceed as normal

Credits to joe roberts for file updates and Napon for his work.


Code:
https://my.pcloud.com/publink/show?code=XZVvdW7ZO707LfnGq6L3cvv6lbVjN7gc9Sak
Bump: ========================================
use this to resize the captcha.

note: this is the catpcha part edited in the template. don't forget to enter your site key of course.


Code:
 <div class="g-recaptcha" data-theme="light" data-sitekey="XXXXXXXXXXXXX" style="transform:scale(0.77);-webkit-transform:scale(0.77);transform-origin:0 0;-webkit-transform-origin:0 0;"></div>
Reply With Quote