Last active
November 29, 2016 13:08
-
-
Save Anan5a/5eeb16e9e682ee63f69f9a31b0a1eb04 to your computer and use it in GitHub Desktop.
A function to verify Google reCAPTCHA response.
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 | |
$response=$_POST['g-recaptcha-response']; | |
$secret='your_secret_key'; | |
$json=g_rec_verify($response,$secret); | |
/* | |
function | |
*/ | |
function g_rec_verify($res,$sec,$ip=null) | |
{ | |
$post = "secret=$sec&response=$res".$ip!=null ?"&remoteip=$ip":""; | |
$ch = curl_init(); | |
$op = array( | |
CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify', | |
CURLOPT_POST => true, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_HTTPHEADER => array( | |
'Content-Type: application/x-www-form-urlencoded; | |
charset=utf-8', 'Content-Length: '.strlen($post)), | |
CURLOPT_POSTFIELDS => $post | |
); | |
curl_setopt_array($ch,$op); | |
$gresp = json_decode(curl_exec($ch)); | |
curl_close($ch); | |
if($gresp->success) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
//cheer | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment