Skip to content

Instantly share code, notes, and snippets.

@dimaspante
Last active February 24, 2021 13:44
Show Gist options
  • Save dimaspante/378e844b6c454f21fbd8865d36da93a7 to your computer and use it in GitHub Desktop.
Save dimaspante/378e844b6c454f21fbd8865d36da93a7 to your computer and use it in GitHub Desktop.
Index:
<?php
define("RECAPTCHA_V3_SITE_KEY", "XXX");
?>
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo RECAPTCHA_V3_SITE_KEY; ?>"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('<?php echo RECAPTCHA_V3_SITE_KEY; ?>', {action: 'contato'}).then(function(token) {
document.getElementById('recaptchaResponse').value = token;
});
});
</script>
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
Send:
$recaptcha_secret = 'ZZZ';
$recaptcha_response = $_POST['recaptcha_response'];
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
$recaptcha = json_decode($recaptcha, true);
if (isset($recaptcha['score']) && $recaptcha['score'] >= 0.5) {
$erro = '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment