Answer the question
In order to leave comments, you need to log in
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;
}
03AHJ_VutTIPGMDR0p1FfaPwfzYGtD6CpxEAfTgRg4cSw8j5HOFFWARVIR6RwGNw4rZlvEvpA78ynbPdwgPpvZDnJL111skCpOXNbaqZbfo6HL1U6ykM2iMyRD2qYDfdZg4yzPbdC4b17kvNVokgoFczIN1Gbnz8tm7vboznoiNPeJeeH6ty_gnyTKMFjzNld8knfoRYufgqmgUvp3wOmewt2LTQKWEepDuhJ3BvSIbbkuyzEswsbueUbM0eb1L0AgsazaR0iO6Iaikwx1gOw69yW2gqLPAdCxnenNxwOiCRauzz5vNKkUso7DkTndYPvFDYbV650RAIug4hRUqIRqk_c1xh4FvsfU67emlD18KsUkL_IyAYcxZWdnK7vqOpOYmr8isFhfiVE2RC_IHwWJY9O13KfubldXY1GikESpTMoZ7MxDYwIrkhKyA3EtXZHAt0_RhVsN
Answer the question
In order to leave comments, you need to log in
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;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question