Created
December 16, 2014 11:24
-
-
Save maximilianoraul/a83951309be26f01d956 to your computer and use it in GitHub Desktop.
Implement the new google reCAPTCHA in PHP applications
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 | |
// 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