Google recaptcha V3 响应数组在实时服务器上为 NULL,但在本地主机上工作
我有以下问题:我的代码可以在本地主机上运行,但不能在实时服务器上运行。
我的代码:
$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));
在本地主机上我得到 array ( 'success' => true, 'challenge_ts' => '2022-03-15T20:24:02Z', 'hostname' => 'localhost', 'score ' => 0.9, 'action' => '已发送', )
在实时服务器上我得到'NULL'
。我尝试显示 file_get_contents 的内容,但我得到“false”并且找不到问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原来这个错误是由服务器的设置引起的。我尝试使用不同的主机,它在本地主机上工作。如果我得到他们的回复,我将发布解决方案。
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.