A simple implementation of Google's reCAPTCHA in PHP. Use this to simply check if the CAPTCHA was correctly solved by the user. Make sure you replace the key value with your secret key.
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 | |
// get reCAPTCHA verification code | |
if (isset($_POST['g-recaptcha-response'])) $captcha = $_POST['g-recaptcha-response']; | |
// check with Google's servers if the captcha is valid | |
$captchaSuccess = false; | |
if (isset($captcha)) { | |
$captchaKey = 'YOUR SECRET KEY'; | |
$captchaURL = 'https://www.google.com/recaptcha/api/siteverify?secret='; | |
$response = json_decode(file_get_contents($captchaURL . $captchaKey . '&response=' . $captcha)); | |
$captchaSuccess = $response->{'success'}; | |
} | |
// now simply check the $captchaSuccess value | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment