Last active
February 8, 2020 13:57
-
-
Save gradosevic/e453e0dbf8bcb3282c2f4ce36a0dfc0d to your computer and use it in GitHub Desktop.
V3 Invisible Captcha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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