首页 > 解决方案 > 简单的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有问题吗?还是我的代码?

标签: phprecaptcha

解决方案


推荐阅读