'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.
Solution 1:[1]
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 2:[2]
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Siva |
| Solution 2 | Tyler2P |
