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>