Jump to content

reCAPTCHA V3 support ?


CastleSoft

Recommended Posts

Would it be possible to add support for V3 (or make an additional) reCaptcha control ?
V3 doesn't require the 'checkbox - I'm not a robot' question.  It just displays a 'hovering' logo right bottom side of the page.
No user interaction is required with v3, which is nice.

The sample howto for php is below:

The basic JS code 

<script src="https://www.google.com/recaptcha/api.js?render=your reCAPTCHA site key here"></script> 

<script> 

    grecaptcha.ready(function() { 

    // do request for recaptcha token 

    // response is promise with passed token 

        grecaptcha.execute('your reCAPTCHA site key here', {action:'validate_captcha'}) 

                  .then(function(token) { 

            // add token value to form 

            document.getElementById('g-recaptcha-response').value = token; 

        }); 

    }); 

</script> 

The basic HTML code 

<form id="form_id" method="post" action="your_action.php"> 

    <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"> 

    <input type="hidden" name="action" value="validate_captcha"> 

    .... your fields 

</form> 

The basic PHP code 

    if(isset($_POST['g-recaptcha-response'])){ 

        $captcha=$_POST['g-recaptcha-response']; 

    } 

    else 

        $captcha = false; 

  

    if(!$captcha){ 

        //Do something with error 

    } 

    else{ 

        $secret = 'Your secret key here'; 

        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret= 

            .$secret.&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']); 

        if($response.success==false) 

        { 

            //Do something with error 

        } 

    } 

... The Captcha is valid you can continue with the rest of your code 

  

 

  • Like 1
  • Upvote 1
Link to comment
Share on other sites

×
×
  • Create New...