1
JAVASCRIPT
function validateCaptcha(){
var responsec = grecaptcha.getResponse();
if(responsec.length == 0){
}else{
$.ajax({
type: "POST",
url: "kingSecure/server.php",
async: false,
data: {
"captcha": responsec
},
success: function(resp) {
if(resp == "success") {
alert("success");
}
else {
alert("fail");
}
}
});
}
}
PHP
$response = $_POST['captcha'];
$privatekey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$param = "https://www.google.com/recaptcha/api/siteverify?secret=".$privatekey."&response=".$response;
$verifyResponse = file_get_contents($param);
$responseData = json_decode($verifyResponse);
if($responseData->success){
echo 'success';
}
HTML
<div class="g-recaptcha" data-sitekey="6Len9TYUAAAAAGmBB_lYT7NDXfWlTxWHCs11cWZ8" data-callback="validateCaptcha"></div>
What appears from code debugging in the browser?
– Evert
Nothing appears. On the Chrome network appears that the POST is OK, IE, was sent correctly.
– Progrando
Try to print the variable dump
$responseData
. Something likevar_dump($responseData)
, just don’t put inside the if.– Juven_v
object(stdClass)[1]
 public 'success' => boolean false
 public 'challenge_ts' => string '2017-11-05T13:28:45Z' (length=20)
 public 'hostname' => string '127.0.0.1' (length=9)
 public 'error-codes' => 
 array (size=1)
 0 => string 'invalid-keys' (length=12)
– Progrando
I think the code is breaking, or the same expires until I send the request to it.
– Progrando