-1

I have the following problem: My code works on localhost but doesn't work on live server.

My code:

$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_secret = 'CAPTCHA_SECRET_KEY'; //secret key

$recaptcha_response = $_POST['g-recaptcha-response'];

$recaptcha = file_get_contents($recaptcha_url . '?secret=' . 
$recaptcha_secret . '&response=' . $recaptcha_response);
$recaptcha = json_decode($recaptcha, true);

//something gets wrong here:
 exit(var_export($recaptcha));

On localhost I get array ( 'success' => true, 'challenge_ts' => '2022-03-15T20:24:02Z', 'hostname' => 'localhost', 'score' => 0.9, 'action' => 'sent', )

On live server I get 'NULL'. I tried to display the contents of file_get_contents but there I get "false" and I can't find the problem.

Ruli
  • 2,592
  • 12
  • 30
  • 40
kopasz
  • 13
  • 3
  • welcome to stackoverflow kopasz, just to be sure, have you whitelisted the live server domain name on google recaptcha admin page? other than that, make sure that the live server can connect to google just fine. though, there might [other stuff](https://stackoverflow.com/a/14801988) you can check. – Bagus Tesa Mar 16 '22 at 09:13

1 Answers1

0

Turns out the error is caused by the settings of the server. I tried with a different host and it works as on localhost. If I get a response from them I will post the solution.

kopasz
  • 13
  • 3