Last active
June 7, 2024 10:27
-
-
Save amityweb/7175c5797d96005dce11e12677364e4b to your computer and use it in GitHub Desktop.
Google ReCaptcha v2 PHP Code
This file contains 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
// Add in to HTML where you want the box to be | |
<script src='https://www.google.com/recaptcha/api.js' async defer></script> | |
<div class="captcha_wrapper"> | |
<div class="g-recaptcha" data-sitekey="YOUR_PUBLIC_KEY"></div> | |
</div> | |
// Add into PHP validation to check the submitted captcha response is a success or fail | |
/* Google ReCaptcha Verification */ | |
$url = 'https://www.google.com/recaptcha/api/siteverify'; | |
$privatekey = "YOUR_PRIVATE_KEY"; | |
$response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']); | |
$data = json_decode($response); | |
if (isset($data->success) AND $data->success==true) | |
{ | |
// Do Success Stuff! | |
} | |
else | |
{ | |
// Do Fail Stuff! | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment