php - 简单的recaptcha 不适用于VPS 服务器,但适用于另一台托管服务器
问题描述
我在 2 个网站中有以下代码。Recaptcha 在普通主机上工作正常,但在 VPS 服务器上不起作用。它真的很奇怪。我检查了 1000 次。
仅供参考,我也安装了 SSL。验证码 v2。VPS 上的 response['success'] 总是假的
索引.php
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<form action="test.php" method="post">
<div class="g-recaptcha" data-sitekey="***"></div>
<input type="submit" name="Submit" id="Submit" value="Submit">
</form>
测试.php
<?php
$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => '***',
'response' => $_POST["g-recaptcha-response"]
);
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
echo "<p>You are a bot! Go away!</p>";
} else if ($captcha_success->success==true) {
echo "<p>You are not not a bot!</p>";
}
?>
我为每个网站使用了不同的密码。Godaddy VPS有问题吗?还是我的代码?
解决方案
推荐阅读
- python - 为列表中的重复元素添加空格
- python - 在一个键上左连接两个字典列表
- javascript - 与 Promise 结合使用时,Async/await 调用返回 undefined
- google-chrome-extension - Chrome 网络服务器扩展 - 在本地运行应用程序
- java - 我创建了一个带有 TextView 和 ImageView 的 Place 对象,但是当我尝试添加一个 place 对象时出现此错误
- nestjs - 更新创建新条目而不是更新它
- python - 不间断的 nginx + 2 个 gunicorns 设置
- python - 如何将 2d 数组添加(不附加)到 3d 数组的每个 2d 数组?
- java - 如何使用 Netbeans 11.1+GlassFish5 创建 SpringMVC5 应用程序?
- xml - 循环和求和来自 XSLT 中不同标记值的值