Skip to content

Instantly share code, notes, and snippets.

@RichardB122
Created November 5, 2016 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardB122/219439a2c7bdca63557f27ffb87ae03e to your computer and use it in GitHub Desktop.
Save RichardB122/219439a2c7bdca63557f27ffb87ae03e to your computer and use it in GitHub Desktop.
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.
<?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