Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Google reCaptcha始终显示';不正确的验证码sol';_Php_Html_Recaptcha - Fatal编程技术网

Php 使用Google reCaptcha始终显示';不正确的验证码sol';

Php 使用Google reCaptcha始终显示';不正确的验证码sol';,php,html,recaptcha,Php,Html,Recaptcha,我正在尝试在我的网站上使用Google reCaptcha,在完成了几个教程之后,我在我的HTML页面上使用了如下内容: <section class="row" id="Contact"> <div class="col-full"> <form method="post" action="contact.php"> <input name="sender" placeholde

我正在尝试在我的网站上使用Google reCaptcha,在完成了几个教程之后,我在我的HTML页面上使用了如下内容:

<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>

为什么我的帖子上没有
recaptcha\u challenge\u字段
recaptcha\u response\u字段
以及如何解决这个问题?

从我看到的情况来看,在检查答案后,你没有
其他
选项。你检查它是否错了,但是没有什么可以告诉它如果用户做对了该怎么做。尝试添加如下内容:

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

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

标题中有:

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

我使用谷歌新的reCaptcha

https://github.com/google/recaptcha
官方代码

它是一个独立的软件包。它与php配合使用非常好

验证失败后,我使用jquery代码重新加载capctha

grecaptcha.reset()

因为recapctha响应在验证后过期,并且captcha不会重新加载,所以它会一次又一次地发送过期响应,直到您不重新加载页面以获取新的captcha代码为止

验证码

require('/path/to/recaptcha/autoload.php');
$recaptcha=new\recaptcha\recaptcha($secret);
$resp=$recaptcha->verify($gRecaptchaResponse,$remoteIp);
如果($resp->issucess()){
}else{$errors=$resp->getErrorCodes();
foreach($errors作为$code){
回显“$code”;
}
echo“注意:错误代码缺少输入响应可能意味着用户没有完成重述;
}

@AndreaLigios是的,我确信我使用了正确的私钥。我只是没有上传其余的代码,因为它与问题无关,
$resp->is\u valid
总是返回false,因为我总是会出错。您是否使用新的复选框recaptcha?如果是这样的话,我可以发布我使用的代码。我想我使用的是最新版本。嗯,
$response['success']
在我尝试时似乎总是错误的。这很奇怪,它对我来说非常有效。确保您已正确输入公钥和密钥。如果这仍然不起作用,请尝试在一个全新的文件中查看结果是否有任何不同。为什么这样做有效而谷歌官方代码无效?这是一种奇怪的魔法。非常感谢你!
 _POST: =========
Array
(
 [g-recaptcha-response] => 03AHJ_VusLbTZVbhMBH2-cyOdbM81IoG7ShDtTmyVa8e34PbghyKaRYnrb4bbeuPoJXFa-2sD5B-UIOWq_zClya-VOtq8iLHXBkAR0PrElQYiQjKTm2POkjci43-yEaenh1tu_M4vKsjJGswKFlVs6IdlWhdVaMdznLBeutgHjiHRBy7fzAi0It0x5IadwMxAqVpmG7F1gRvUcQmakij4ObTqPUK4lPdc84HkkKmY62uJ45d8DwKSeR2ifRg6wL9JFxpcZkjSp4oIlltin2uCMiBDU58QQQLLKPJuSKcmm-N5p7OEt7E6gc4UZyTLpKrJ-9mMUusvLpixwFHop0e5155vEZssxzu6Zizo-LyB1mX3XOrQ8LEceydssgLvl9gJBC4f9zDBKPQdLmjfxVKdPCXLtUZVNbMDYe7cNL7gsgwJC-hLbZYTh6UV1nUdKnFnkHAACjI7M28hpKWdiyIwcJ5UAzTMPfIllMw
)

=========
if (!$resp->is_valid) {
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")");
}
else {
    //Code for success here
}
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="g-recaptcha" data-sitekey="PUBLIC_KEY_HERE"></div>
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
}
require('/path/to/recaptcha/autoload.php');

$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
} else { $errors = $resp->getErrorCodes();
foreach ($errors as $code) {
echo "<div class=\"alert alert-danger\">$code</div>";
}
echo "<p><strong>Note:</strong> Error code <tt>missing-input-response</tt> may mean the user just didn't complete the reCAPTCHA.</p>";
}