Forked from jonathanstark/verify-google-recaptcha-with-php
Last active
July 26, 2017 11:50
-
-
Save dskanth/55e70cb9a5ff45874c896add7afc6399 to your computer and use it in GitHub Desktop.
Verify Google reCAPTCHA with PHP
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
# | |
# Verify captcha | |
$post_data = http_build_query( | |
array( | |
'secret' => CAPTCHA_SECRET, | |
'response' => $_POST['g-recaptcha-response'], | |
'remoteip' => $_SERVER['REMOTE_ADDR'] | |
) | |
); | |
$opts = array('http' => | |
array( | |
'method' => 'POST', | |
'header' => 'Content-type: application/x-www-form-urlencoded', | |
'content' => $post_data | |
) | |
); | |
$context = stream_context_create($opts); | |
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context); | |
$result = json_decode($response); | |
if (!$result->success) { | |
throw new Exception('Oops! CAPTCHA verification failed. Please contact administrator at: dskanth.99 at google mail dot com', 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment