1
Hello guys, I’m having this problem with the recaptcha on a system implemented in PHP, the code below as this the code.
Recaptcha in HTML is like this, I decided to leave this script there also for organization.
<div class="g-recaptcha" id="captcha" data-sitekey="6LdAHWcUAAAAAPFO6j34mmWwhRer0K8Kp8901jM-" data-error-callback="errorRecaptcha" data-expired-callback="recaptchaExpired"></div>
<script>
// Função que bloqueia o submit quando o recaptcha expira
function recaptchaExpired(){
alert("ReCaptcha expirado, por favor verifique novamente !");
setTimeout(function(){location.reload()}, 500);
}
function errorRecaptcha(){
alert("Erro ao Validar Recaptcha");
setTimeout(function(){location.reload()}, 500);
}
</script>
is in PHP I perform this to validate
$captcha = $_POST['g-recaptcha-response'];
$secret_key = "***";
$content = http_build_query(array(
'secret' => $secret_key,
'response' => $captcha,
));
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'content' => $content
)
));
//A função abaixo realiza o envio da resposta captcha para verificação e tem como retorno um JSON
$result_json = file_get_contents('https://www.google.com/recaptcha/api/siteverify', null, $context);
$array_result = json_decode($result_json, true);
//Valida se o retorno do servidor é true ou false para o captcha informado
$resp_captcha = intval($array_result['success']);
if ($resp_captcha === 1) {
Higor, if any answer has solved your problem you can mark as accepted by clicking on the green V side of the chosen points. Or, if you want, you can leave it open for a while if you want more alternatives, but it is good that after it is resolved you mark some to close the subject. Learn more in "How and why to accept an answer".
– João Pedro Schmitz