Skip to content

Instantly share code, notes, and snippets.

@man4toman
Created Mar 13, 2022
Embed
What would you like to do?
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