A
A
Alexander2015-06-29 23:36:42
PHP
Alexander, 2015-06-29 23:36:42

What am I doing wrong when checking the reCaptcha result?

Installed reCaptcha on the site and connected. But when checking the result, an error message comes in response: invalid-input-response.
I check like this:

if($rcvf = curl_init())
{
      curl_setopt($rcvf, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
      curl_setopt($rcvf, CURLOPT_POST, true);
      curl_setopt($rcvf, CURLOPT_POSTFIELDS, "secret=" . $reCaptcha_privatekey . "&response=" . $cresp . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
      curl_setopt($rcvf, CURLOPT_RETURNTRANSFER, true);
      $rcvq = curl_exec($rcvf);
      curl_close($rcvf);
      $rcvr = json_decode($rcvq, true);
      if($rcvr['success']) return 1;
      else return 0;
}

The $cresp variable is the user's response. It is passed to this function for verification directly from the form handler script. The answer seems to be correct. It has, for example, the following form:
03AHJ_VutTIPGMDR0p1FfaPwfzYGtD6CpxEAfTgRg4cSw8j5HOFFWARVIR6RwGNw4rZlvEvpA78ynbPdwgPpvZDnJL111skCpOXNbaqZbfo6HL1U6ykM2iMyRD2qYDfdZg4yzPbdC4b17kvNVokgoFczIN1Gbnz8tm7vboznoiNPeJeeH6ty_gnyTKMFjzNld8knfoRYufgqmgUvp3wOmewt2LTQKWEepDuhJ3BvSIbbkuyzEswsbueUbM0eb1L0AgsazaR0iO6Iaikwx1gOw69yW2gqLPAdCxnenNxwOiCRauzz5vNKkUso7DkTndYPvFDYbV650RAIug4hRUqIRqk_c1xh4FvsfU67emlD18KsUkL_IyAYcxZWdnK7vqOpOYmr8isFhfiVE2RC_IHwWJY9O13KfubldXY1GikESpTMoZ7MxDYwIrkhKyA3EtXZHAt0_RhVsN

In php.ini the post_max_size variable is 999M. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg ak-o, 2015-06-30
@zkelo

I have this simple class:

class ReCaptcha {

    private $captcha_key;
    private $captcha_url;

    public function __construct() {
        $this->captcha_key = APP_CAPTCHA_KEY;
        $this->captcha_url = APP_CAPTCHA_URL;
    }

    public function validateCaptcha($captcha) {
        $validateCaptcha = file_get_contents($this->captcha_url.'?secret='.$this->captcha_key.'&response='.$captcha.'&remoteip='.$_SERVER['REMOTE_ADDR']);
        $validateCaptcha = json_decode($validateCaptcha);
        if(!$validateCaptcha->success) {
            throw new Exception('Wrong captcha');
        }
        return $validateCaptcha->success;
    }

}

I haven’t climbed into it for a long time, maybe something has changed, but judging by my class, the response should be json , and not some kind of muddy string.
If you want to use Curl in the answer above, see how it is done, there is also Curl, by the way, and sockets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question