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>
$responseData
. Algo comovar_dump($responseData)
, só não coloque dentro do if.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)