Why does reCAPTCHA v3 return 0 ? In custom AJAX registration form

Question

The secret key is correct, but it returns 0 and it doesn’t seem to work properly, what needs to be fixed or redone?

enter image description here

PHP code:
// add_recaptcha_api

add_action( ‘wp_enqueue_scripts’, ‘add_recaptcha_api’, 11 );

function add_recaptcha_api() {
wp_deregister_script( ‘add_recaptcha_api’ );
wp_register_script( ‘add_recaptcha_api’, ‘https://www.google.com/recaptcha/api.js?render=6LdwamUbAAAAAJE-IEtIOT9VrbKSFi7U7Sfj62KR’);
wp_enqueue_script( ‘add_recaptcha_api’ );
}

function registration_recaptcha(){

$recaptcha_url="https://www.google.com/recaptcha/api/siteverify";
$recaptcha_secret="secret";
$recaptcha_response = $_POST['recaptcha_response'];
$recaptcha = file_get_contents($recaptcha_url . '?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response);
$recaptcha = json_decode($recaptcha);

if ($recaptcha->success == true && $recaptcha->score >= 0.5 && $recaptcha->action == “registration_recaptcha’) {

}

else

{
    

}

}

add_action( “wp_ajax_nopriv_registration_recaptcha”, “registration_recaptcha” );

Html code:

JS code:

enter image description here

0
Anrisssss 1 month 2022-08-28T04:58:25-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse