Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //validate
- $receivedRecaptcha = $_POST['recaptchaRes'];
- $google_secret = "Yoursecretgooglepapikey";
- $verifiedRecaptchaUrl = 'https://www.google.com/recaptcha/api/siteverify?secret='.$google_secret.'&response='.$receivedRecaptcha;
- $handle = curl_init($verifiedRecaptchaUrl);
- curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); // not safe but works
- //curl_setopt($handle, CURLOPT_CAINFO, "./my_cert.pem"); // safe
- $response = curl_exec($handle);
- $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
- curl_close($handle);
- if ($httpCode >= 200 && $httpCode < 300) {
- if (strlen($response) > 0) {
- $responseobj = json_decode($response);
- if(!$responseobj->success) {
- echo "reCAPTCHA is not valid. Please try again!";
- }
- else {
- echo "reCAPTCHA is valid.";
- }
- }
- } else {
- echo "curl failed. http code is ".$httpCode;
- }
Add Comment
Please, Sign In to add comment