Created
August 12, 2016 11:06
-
-
Save emmgfx/d8eff2ee4b214d8e7539379ec2d3de70 to your computer and use it in GitHub Desktop.
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 | |
function checkRecaptcha($recaptcha_response){ | |
$url = 'https://www.google.com/recaptcha/api/siteverify'; | |
$fields = array( | |
'secret' => 'YOUR_SECRET_KEY', | |
'response' => $recaptcha_response, | |
); | |
$fields_string = ''; | |
foreach($fields as $key => $value) { | |
$fields_string .= $key.'='.$value.'&'; | |
} | |
rtrim($fields_string, '&'); | |
$ch = curl_init(); | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch,CURLOPT_URL, $url); | |
curl_setopt($ch,CURLOPT_POST, count($fields)); | |
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); | |
//execute post | |
$recaptcha_query = json_decode(curl_exec($ch), true); | |
//close connection | |
curl_close($ch); | |
return ($recaptcha_query['success'] == 1); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment