Skip to content

Instantly share code, notes, and snippets.

@man4toman
Created March 13, 2022 23:21
Show Gist options
  • Save man4toman/a67516d2e6f26aee76a8061a99d4bc85 to your computer and use it in GitHub Desktop.
Save man4toman/a67516d2e6f26aee76a8061a99d4bc85 to your computer and use it in GitHub Desktop.
Google recaptcha v3 - PHP
<?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
}
<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