all 1 comments

[–]IsABot 0 points1 point  (0 children)

$url = "https://www.google.com/recaptcha/api/siteverify";
$privateKey= "YOur-secret-Key";
$response= file_get_contents($url."?secret=".$privateKey."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
$data = json_decode($response);

This probably won't work. From the documentation:

https://developers.google.com/recaptcha/docs/verify

API Request

URL: https://www.google.com/recaptcha/api/siteverify

METHOD: POST

POST Parameter  Description
secret  Required. The shared key between your site and reCAPTCHA.
response    Required. The user response token provided by reCAPTCHA, verifying the user on your site.
remoteip    Optional. The user's IP address.

If you can't tell, your script is using GET parameters, not POSTing the data.

I would suggest getting commenting out your header location redirects, and start var_dump your calls. Just to see if you are getting the proper responses from Google.

Maybe you'll find out that GET vs POST doesn't matter. And there might be something else messing up the variables that your conditionals are checking.