3

Recently a client told me his website's reCAPTCHA was no longer working. After investigating, I found out that Google changed it. I upgraded their site using the new documentation from Nov 19, 2014, but it always gives me a 403 error. I tried submitting just the secret key and that returned a JSON result with a false and an error. I did the same by just submitting the response from the g-recaptcha-response field and it also returned a JSON result with the error. As soon as I put both of them into a string using http_build_query, I get a 403 forbidden from Google.

I am using the new http://www.google.com/recaptcha/api/siteverify URL. I am submitting to it using PHP cURL using the following code:

    $post_data = array('response'=>$response, 'secret'=>$privatekey);
    $curlPost = http_build_query($post_data, '', '&');

    $ch = curl_init();

    //Set the URL of the page or file to download.
    $url = 'http://www.google.com/recaptcha/api/siteverify';

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);

    $data_json = curl_exec($ch);

Any help would be greatly appreciated.

1
  • What's your JSON result, exactly? (Also, I don't know much about reCAPTCHA, but from the looks of the documentation, shouldn't you be using a GET request, rather than POSTing the parameters?) Nov 24, 2014 at 21:59

2 Answers 2

6

You have to use https, so the correct URL is:

$url = 'https://www.google.com/recaptcha/api/siteverify';

This should fix the 403 error.

2
  • I am using https url : google.com/recaptcha/api/siteverify but i am getting error Tried all: 1 addresses, but could not connect over HTTPS to server: google.com port: 443. I am using Java at server-side to validate the g-recaptcha-response string. What could be the reason for this error? Nov 5, 2017 at 6:58
  • But then I get could not open socket error hahahhaha Apr 18, 2018 at 15:33
0

Just droping this info, as encountered and the reason was: recaptcha gem starting from v5.0 changed used siteverify host from google.com to recaptcha.net
code repo

So might be needed configuration in FW.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.