Skip to content

Instantly share code, notes, and snippets.

@maximilianoraul
Created December 16, 2014 11:24
Show Gist options
  • Save maximilianoraul/a83951309be26f01d956 to your computer and use it in GitHub Desktop.
Save maximilianoraul/a83951309be26f01d956 to your computer and use it in GitHub Desktop.
Implement the new google reCAPTCHA in PHP applications
<?php
// reCAPTCHA
// https://www.google.com/recaptcha/intro/index.html
if (isset($_POST['g-recaptcha-response']) && filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP)) {
$captcha = json_decode(file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=your_secret_key&response=' . $_POST['g-recaptcha-response'] . '&remoteip=' . $_SERVER['REMOTE_ADDR']), TRUE);
if (isset($captcha['success']) && $captcha['success'] === TRUE) {
//Captcha OK
} else {
//Captcha Error
//Stop Script
}
} else {
//Error, not valid parameters
//Stop script
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment