Created
March 13, 2022 23:21
-
-
Save man4toman/a67516d2e6f26aee76a8061a99d4bc85 to your computer and use it in GitHub Desktop.
Google recaptcha v3 - PHP
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
<?php | |
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ | |
$secret_key = 'SECERET_KEY'; | |
$verify_captcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret_key.'&response='.$_POST['g-recaptcha-response']); | |
$verify_response = json_decode($verify_captcha); | |
if($verify_response->success){ | |
//success | |
}else{ | |
// check the captcha checkbox | |
} | |
}else{ | |
// empty captcha | |
} |
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
<form method="post" action="check.php"> | |
<script src="https://www.google.com/recaptcha/api.js" async defer></script> | |
<div class="g-recaptcha" data-sitekey="SITE_KEY"></div> | |
<input type="submit" value="Submit"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment