reCaptcha不发布挑战或回应

时间:2013-11-13 03:06:25

标签: php html recaptcha

我是reCaptcha的新手,我有一些麻烦让它发布。

<form action="createUser.php" method="post">

    <tr>
        <td>Username</td>
        <td>
            <input type="text" name="username">
        </td>

    </tr>
    <tr>
        <td>Password</td>
        <td><input type="password" name="password"></td>

    </tr>

    <tr>
        <td>Confirm Password</td>
        <td><input type="password" name="confirmPassword"></td>

    </tr>

    <tr>
        <td>
            <script type="text/javascript"
                    src="http://www.google.com/recaptcha/api/challenge?k=6LcjLeoSAAAAAF5fo6FA8h6z6796Yxg4bA-Ggh7o">
            </script>
            <noscript>
                <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LcjLeoSAAAAAF5fo6FA8h6z6796Yxg4bA-Ggh7o"
                        height="300" width="500" frameborder="0"></iframe><br>
                <textarea name="recaptcha_challenge_field" rows="3" cols="40">
                </textarea>
                <input type="hidden" name="recaptcha_response_field"
                       value="manual_challenge">
            </noscript>
        </td>
    </tr>

    <tr>
        <td><input type="submit" value="Register"></td>
    </tr>

</form>

在createUser.php上,它表示reCaptcha challenge字段和响应字段为空,并且使用PHP风暴调试它们也不包含在createUser.php的POST中,我似乎无法弄清楚为什么他们不会不包括在POST中。关于什么是错的任何想法?

2 个答案:

答案 0 :(得分:0)

如果您计划显示reCAPTCHA,请使用标准API。请检查以下链接。

https://developers.google.com/recaptcha/docs/display

答案 1 :(得分:0)

1.将action="createUser.php"更改为action="verify.php"

<td>
            <script type="text/javascript"
                    src="http://www.google.com/recaptcha/api/challenge?k=6LcjLeoSAAAAAF5fo6FA8h6z6796Yxg4bA-Ggh7o">
            </script>
            <noscript>
                <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LcjLeoSAAAAAF5fo6FA8h6z6796Yxg4bA-Ggh7o"
                        height="300" width="500" frameborder="0"></iframe><br>
                <textarea name="recaptcha_challenge_field" rows="3" cols="40">
                </textarea>
                <input type="hidden" name="recaptcha_response_field"
                       value="manual_challenge">
            </noscript>
        </td>

<td>
<?php
          require_once('recaptchalib.php');
          $publickey = "Your Public Key"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>
</td>

2.制作verify.php文件

3.在verify.php文件中添加以下代码 -

<?php
  require_once('recaptchalib.php');
  $privatekey = "Your Private Key";
  $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

mysql_connect("localhost","Database Username","Password");
mysql_select_db("Database name");
$name=$_POST['name'];
$comment=$_POST['comment'];
$date=$_POST['date'];
$submit=$_POST['submit'];

$dbLink = mysql_connect("localhost", "Database usename", "password");
    mysql_query("SET character_set_client=utf8", $dbLink);
    mysql_query("SET character_set_connection=utf8", $dbLink);

if($comment)
{
$insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment') ");  
    ?>
<script type="text/javascript">
window.location = "Where You want to redirect User after successful signup";
</script>      
    <?php
}
else
{
echo '<div class="err">' . "Please Fill out all Fields" . '</div>';
}
}
?>

注意:不要只是复制代码,这只是一个很好的提示。 在// Your code here to handle a successful verification之后的verify.php中 只需添加将用户数据插入数据库表的代码。