We are using reCAPTCHA v2 on a php site. Form is getting submitted and verified, but nothing is being returned. Upon visiting the recaptcha endpoint at https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']
, it is showing the json as success: true. However, the $response object is empty.
{ "success": true, "challenge_ts": "2023-03-13T21:41:04Z", "hostname": "example.com" }
form.php:
<FORM ACTION="Submit.php" METHOD="POST" name="pvform" onSubmit="return verify()" autocomplete="off">
...
<td height="21" align="left"><div class="g-recaptcha" data-sitekey="my_key"></div></td>
</FORM>
And in the submit handler,
Submit.php
<?php
if($_SERVER["REQUEST_METHOD"] === "POST")
{
$recaptcha_secret = "my_secret";
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
$response = json_decode($response, true);
PHP is also returning a warning on the file_get_contents() line:
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/site/forms/Submit.php on line 30
Warning: file_get_contents(https://www.google.com/recaptcha/api/siteverify?secret=<my_secret>&response=<response string>): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/site/forms/Submit.php on line 30