代码之家  ›  专栏  ›  技术社区  ›  Anriëtte Myburgh

需要有关recaptcha的帮助-继续获取错误的captcha sol

  •  8
  • Anriëtte Myburgh  · 技术社区  · 15 年前

    我正在尝试向我的网站添加摘要,但继续 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>
    

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

    蒂亚

    6 回复  |  直到 7 年前
        1
  •  19
  •   Anriëtte Myburgh    13 年前

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

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

    我把它改成了:

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

    因为这个开关,突然 recaptcha_response_field recaptcha_challenge_field 正在将值过账回表单。

    我想不出这是为什么,因为我所有的表单变量都在切换之前被发布了回来。

    谢谢你的指点。

        2
  •  9
  •   Josh    15 年前

    如果您发布了两次检查-例如一次从javascript和一次通过php,第二次检查将失败,因为api只允许解决方案返回有效的一次。

    希望能有所帮助, 乔希

        3
  •  5
  •   den    14 年前

    这是因为表单不能位于tr的外部…..它必须位于表的外部…..表单不能插入到表中,但是可以插入到td中。

        4
  •  2
  •   esteve    14 年前

    在我的例子中,错误是设置表单而不指定:

    方法=“POST”

    干杯!

        5
  •  0
  •   TigerTiger    15 年前

    你确定你输入的是正确的单词吗?

    这个是从 recaptcha website :

    Line 1       "true" or "false". True if the reCAPTCHA was successful
    Line 2  if Line 1 is false, then this string will be an error code. reCAPTCHA can 
        display the error to the user (through the error parameter of api.recaptcha.net/challenge).
         Implementations should not depend on error code names, 
    as they may change in the future.
    
    
        Example: If your response looks like this:
    
        false
        **incorrect-captcha-sol**
    
        ... you can add '&error=incorrect-captcha-sol' to the challenge request URL, 
    and the user will get an error code.
    
        6
  •  0
  •   rok    7 年前

    在脚本的根目录中,将php.ini设置为:

    允许打开