vendredi 24 juillet 2020

Why is my variable value set to false even after it's set to true?

I am trying to implement google reCAPTCHA. The issue is even when ($Return->success == true && $Return->score >= 0.5) is equal to true, when i should be getting $isOK = true, I get $isOK = false.

I tried a lot, but I am still getting this value set to false. Is there something I am doing wrong over here?

$captchaVerified = false;
if(isset($_POST['tokenVal'])){
    function getCaptcha($tokenV,$secretKey){
        $Response =  file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".urlencode($secretKey)."&response=".urlencode($tokenV));
        $Return = json_decode($Response);
        /* global $captchaVerified;*/
        if ($Return->success == true && $Return->score >= 0.5) {
            $captchaVerified = true;
        } else {
            $captchaVerified = false;
        }
        return $captchaVerified;
    }
   $isOK = getCaptcha($_POST['tokenVal'],$secretKey);
}

Aucun commentaire:

Enregistrer un commentaire