Google recaptcha V3 响应数组在实时服务器上为 NULL,但在本地主机上工作

发布于 2025-01-14 09:27:59 字数 753 浏览 3 评论 0原文

我有以下问题:我的代码可以在本地主机上运行,​​但不能在实时服务器上运行。

我的代码:

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往事风中埋 2025-01-21 09:27:59

原来这个错误是由服务器的设置引起的。我尝试使用不同的主机,它在本地主机上工作。如果我得到他们的回复,我将发布解决方案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文