Skip to content

Instantly share code, notes, and snippets.

@gradosevic
Last active February 8, 2020 13:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gradosevic/e453e0dbf8bcb3282c2f4ce36a0dfc0d to your computer and use it in GitHub Desktop.
V3 Invisible Captcha
<form>
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response" />
<script src="https://www.google.com/recaptcha/api.js?render=PUBLIC_KEY"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('PUBLIC_KEY', {action: 'homepage'}).then(function(token) {
document.getElementById('g-recaptcha-response').value = token;
});
});
</script>
</form>
<?php
//Validate recaptcha
$verifyResponse = file_get_contents(
'https://www.google.com/recaptcha/api/siteverify?secret=SECRET_KEY&response=' . $_REQUEST['g-recaptcha-response']
);
$responseData = json_decode($verifyResponse);
if (!$responseData->success):
$errors = [ 'Invalid captcha' ];
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment