Google reCAPTCHA - 不断收到“incorrect-captcha-sol”

新手上路,请多包涵

我正在尝试向我的站点添加 reCAPTCHA,但在我提交答案时不断收到 incorrect-captcha-sol 错误。

谁能告诉我以下操作是否正确?

我有一个通用的 index.php,其中包括 contact.php。在 contact.php 中,我插入了以下代码:

 require_once('recaptchalib.php');
$publickey = "XXXX";
$privatekey = "XXXX";

//the response from reCAPTCHA
$resp = null;
//the error code from reCAPTCHA, if any
$error = null;

if ($_POST['submit']) {
    $message = $_POST['message_txt'];
    $name = $_POST['name_txt'];
    $email = $_POST['email_txt'];

    $emailBody = $message;
    $to = 'xx';
    $from = $name.' <'.$email.'>';
    $subject = 'XX Website Enquiry';
    $headers = 'From: '.$from;

    $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);

    if ($resp->is_valid) {
        echo 'captcha correct';
        if (mail($to,$subject,$emailBody,$headers)) {
            //echo 'mail sent';
            $confirmation = 'sent';
        }
        else {
            //echo 'mail not sent';
            $confirmation = 'error';
        }
    } else {
        # set the error code so that we can display it. You could also use
        # die ("reCAPTCHA failed"), but using the error message is
        # more user friendly

        $error = $resp->error;

        echo $error;
    }
}

在我的 html 中,我插入了这样的验证码:

 <form name="contactForm" method="post" action="index.php?id=contact&action=submit#contact">
    <tr><td>Name</td><td><div align="right">
        <input type="text" name="name_txt" class="input">
        </div></td></tr>
    <tr><td>Email</td><td><div align="right">
        <input type="text" name="email_txt" class="input">
    </div></td></tr>
    <tr><td height="10"></td></tr>
    <tr><td colspan="2">Message</td></tr>
    <tr><td colspan="2"><textarea name="message_txt" class="textarea" style="width:200px; height:100px"></textarea></td></tr>
    <tr><td colspan="2"><?php echo recaptcha_get_html($publickey, $error); ?></td></tr>
    <tr><td colspan="2" style="padding-top:10px;"><input type="image" src="images/header_06.gif" name="submit" value="submit"></td></tr>
</form>

我看不出我做错了什么,但希望得到任何帮助。

原文由 Anriëtte Myburgh 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 816
2 个回答

我已经解决了这个问题,这是我遇到的最不寻常的事情之一,我以前的语法是:

 <table>
  <form>
    <tr><td></td></tr>
  </form>
</table>

我把它改成这样:

 <form>
  <table>
    <tr><td></td></tr>
  </table>
</form>

由于此开关, recaptcha_response_fieldrecaptcha_challenge_field 突然将值发回表单。

我想不通为什么会这样,因为所有我的表单变量都在切换之前发回了。

谢谢大家指点。

原文由 Anriëtte Myburgh 发布,翻译遵循 CC BY-SA 4.0 许可协议

你是从你的 本地主机上 做的吗?

我通过将 localhost 添加到允许的域中以在 google reCaptcha 设置中进行验证来解决此问题

域名验证码设置

原文由 Aditya Kresna Permana 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题