使reCAPTCHA在同一页面上工作(index.php)

时间:2014-01-07 13:39:41

标签: forms recaptcha

你好我每个人都有一个表格,我想给它添加reCAPTCHA。 这是我的表格

<form action="index.php" method="POST">
    <div class="header"></div>
    <div class="headerimg">
        <a href="http://sonymobile.comule.com/"><img border="0" src="logo.png" alt="AUD Confession" width="auto" height="auto"></a>
        <div class="headertxt">Confession</div>
    </div>
    <table font-family="inherit">
        <tr><td class="comm" colspan="2">Comment: </td></tr>
        <tr><td colspan="5"><textarea name="comment" rows="5" cols="50" id="comments" class="common" autofocus></textarea></td></tr>
        <tr><td><?php
          require_once('recaptchalib.php');
          $publickey = "6Lc1RewSAAAAAO2Emd1_ICM5qUssQdfqF0vRiCE9"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?></tr></td>
        <tr><td colspan="2"><input type="submit" name="submit" class="myButton" value="SUBMIT"></td></tr>
    </table> 
</form>

问题是reCAPTCHA会在action="verify.php"上检查它并显示它是否正确,但不要在index.php上提交表单值。

verify.php上的代码

<?php
  require_once('recaptchalib.php');
  $privatekey = "6Lc1RewSAAAAAPBsu1AnNhJpIbS64XR0fLqEioVb";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }
  ?>

我希望reCAPTCHA检查同一页面i:e; action="index.php"。 请帮忙。 或者提出类似的建议。

1 个答案:

答案 0 :(得分:0)

我自己想出来并得到了解决方案。 我所要做的就是添加一些代码代替 // Your code here to handle a successful verification  将用户数据插入数据库的php代码。