简体   繁体   中英

Google ReCaptch [invalid-input-response] error

So we are using google ReCaptcha in our site, but for one country it's returning as [invalid-input-response] error, but for the same code flow for another site it's working fine. I saw others also raised this similar issue but there are no responses, also google ReCaptcha support mail is also invalid in their support site. I hope I get some solution/response to my query here. I checked the site key and the secret key and they are correct. Again I repeat, this code worked perfectly. What can be causing this issue?

Any kind of response is appreciated. Thanks.

This invalid-input-response-error is caused when the google recaptcha response that you are sending from client browser to google api for verification is not proper one. it might be empty or tampered before sending.

Solution: From what I saw and tested from this link -> https://groups.google.com/g/recaptcha/c/yEPN3d9ylT8 in Cyber's comment, the CURLOPT_HTTPHEADER was the differentiator. But in my case I didn't need to add the IP for that.


My test using PHP. This is my code that worked.

$url = 'https://www.google.com/recaptcha/api/siteverify';
$secret = "YOUR_SECRET_KEY";
$reponse = $request['g-recaptcha-response'];
$variaveis = "secret=".$secret."&response=". $reponse;

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_POST,1);
curl_setopt($curl, CURLOPT_POSTFIELDS,$variaveis);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; 
charset=utf-8', 'Content-Length: ' . strlen($variaveis)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);

$resposta = curl_exec($curl);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM