使用Google reCaptcha总是显示'incorrect-captcha-sol' [英] Using Google reCaptcha always shows 'incorrect-captcha-sol'

查看:1705
本文介绍了使用Google reCaptcha总是显示'incorrect-captcha-sol'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的网站上使用Google reCaptcha,并在遵循几个教程之后,在我的HTML页面上使用了以下内容:

I'm trying to use Google reCaptcha on my website and after following several tutorials, I'm using as follow on my HTML page:

<section class="row" id="Contact">
        <div class="col-full">
             <form method="post" action="contact.php">
                <input name="sender" placeholder="Name" size="30"><br><br>
                <input name="senderEmail" placeholder="Email" size="30"><br><br>
                <textarea rows="10" cols="30" name="message" placeholder="Message"></textarea><br><br>
                <div class="g-recaptcha" data-sitekey="6LdFOQcTAAAAABKsku3bD6Mp3HuGYNDRN1tLlSkw"></div><br>
                <input type="submit" name="submit">
            </form>
        </div>
</section>

< head> 标记:

    <script src='https://www.google.com/recaptcha/api.js'></script>

表单加载以下PHP脚本,如 Google的教程

The form loads the following PHP script as shown on Google's tutorial:

<?php

require_once('recaptchalib.php');

echo "<pre> _POST: =========\n";
print_r($_POST);
echo "\n=========\n</pre>";

$privatekey = "privatekey";
$resp = recaptcha_check_answer ($privatekey,
                             $_SERVER["REMOTE_ADDR"],
                             $_POST["recaptcha_challenge_field"],
                             $_POST["recaptcha_response_field"]);
if (!$resp->is_valid)
{
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
    "(reCAPTCHA said: " . $resp->error . ")");
}

?>

问题是我总是得到错误错误 - captcha-sol 并且无法理解原因。我从PHP脚本中得到的输出是:

The problem is I always get the error incorrect-captcha-sol and can't understand why. the output I get from the PHP script is:

 _POST: =========
Array
(
 [g-recaptcha-response] => 03AHJ_VusLbTZVbhMBH2-cyOdbM81IoG7ShDtTmyVa8e34PbghyKaRYnrb4bbeuPoJXFa-2sD5B-UIOWq_zClya-VOtq8iLHXBkAR0PrElQYiQjKTm2POkjci43-yEaenh1tu_M4vKsjJGswKFlVs6IdlWhdVaMdznLBeutgHjiHRBy7fzAi0It0x5IadwMxAqVpmG7F1gRvUcQmakij4ObTqPUK4lPdc84HkkKmY62uJ45d8DwKSeR2ifRg6wL9JFxpcZkjSp4oIlltin2uCMiBDU58QQQLLKPJuSKcmm-N5p7OEt7E6gc4UZyTLpKrJ-9mMUusvLpixwFHop0e5155vEZssxzu6Zizo-LyB1mX3XOrQ8LEceydssgLvl9gJBC4f9zDBKPQdLmjfxVKdPCXLtUZVNbMDYe7cNL7gsgwJC-hLbZYTh6UV1nUdKnFnkHAACjI7M28hpKWdiyIwcJ5UAzTMPfIllMw
)

=========

为什么我没有 recaptcha_challenge_field recaptcha_response_field 字段在我的POST上,我该如何解决它?

Why don't I have recaptcha_challenge_field or recaptcha_response_field fields on my POST and how can I solve it?

推荐答案

我用于我的recaptcha的代码如下所示:

The code I used for my recaptcha is as follows:

标题如下:

<script src='https://www.google.com/recaptcha/api.js'></script>

这就是您希望实际收回的地方:

This goes where you want the actual recaptcha to be:

<div class="g-recaptcha" data-sitekey="PUBLIC_KEY_HERE"></div>

您可以将其添加到div以更改主题: data-theme =theme

You can add this to the div to change the theme: data-theme="theme"

这是PHP脚本:

And this is the PHP script:

if(isset($_POST['g-recaptcha-response']))
$captcha=$_POST['g-recaptcha-response'];
if(!$captcha){
    //Captcha hasn't been checked
}
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=SECRET_KEY_HERE&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
if($response['success'] == false){
    //Captcha incorrect
}
else {
    //Success code here
}

这篇关于使用Google reCaptcha总是显示'incorrect-captcha-sol'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆