需要帮助reCAPTCHA - 不断变得不正确 - captcha-sol [英] Need help with reCAPTCHA - keep getting incorrect-captcha-sol

查看:284
本文介绍了需要帮助reCAPTCHA - 不断变得不正确 - captcha-sol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的网站添加reCAPTCHA,但在提交答案时,一直收到错误 - captcha-sol 错误。



任何人都可以告诉我,我是否正确执行以下操作?



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

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

// reCAPTCHA的响应
$ resp = null;
// reCAPTCHA的错误代码,如果有的话
$ 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网站查询';
$ 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 {
#设置错误代码,以便我们可以显示它。您也可以使用
#die(reCAPTCHA failed),但使用错误消息是
#更加便于用户使用

$ error = $ resp->错误;

echo $ error;
}

}

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

 < form name =contactFormmethod =postaction = ?的index.php ID =接触&安培;行动=提交#接触> 
< tr>< td>名称< / td>< td>< div align =right>
< input type =textname =name_txtclass =input>
< / div>< / td>< / tr>
< tr>< td>电子邮件< / td>< td>< div align =right>
< input type =textname =email_txtclass =input>
< / div>< / td>< / tr>
< tr>< td height =10>< / td>< / tr>
< tr>< td colspan =2>讯息< / td>< / tr>
< tr>< td colspan =2>< / textarea>< textarea name =message_txtclass =textareastyle =width:200px; height:100px< ; / TD>< / TR>
< tr>< td colspan =2><?php echo recaptcha_get_html($ publickey,$ error); ?>< / TD>< / TR>
< tr>< td colspan =2style =padding-top:10px;>< input type =imagesrc =images / header_06.gifname =submit值= 提交 >< / TD>< / TR>
< / form>

我看不出我做错了什么,但会感谢任何有建设性的批评。



TIA

解决方案

我解决了这个问题,它是最不寻常的事情之一我碰到过,我的语法是:

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

我将其更改为:

 <形式> 
< table>
< tr>< td>< / td>< / tr>
< / table>
< / form>

由于此切换,突然间 recaptcha_response_field recaptcha_challenge_field 将值重新发送回表单。



我不明白为什么会这样,因为所有MY表单变量都发布了返回之前切换。

感谢所有的指针。


I am trying to add a reCAPTCHA to my site, but keep getting incorrect-captcha-sol error when I submit the answer.

Can anyone tell me if I am correct in doing the following?

I have a generic index.php, which includes contact.php. In contact.php I have inserted the following code:

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

}

In my html I inserted the CAPTCHA like this:

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

I cannot see that I am doing anything wrong, but would appreciate any constructive criticism.

TIA

解决方案

I have solved this, it is one of the most unusual things I have come across, my syntax was previously:

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

I changed it to this:

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

Because of this switch, suddenly the recaptcha_response_field and recaptcha_challenge_field are posting values back to the form.

I cannot think why this because all MY form variables got posted back before the switch.

Thanks all for the pointers.

这篇关于需要帮助reCAPTCHA - 不断变得不正确 - captcha-sol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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