0

我是 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 挑战字段和响应字段为空,并且使用 PHP Storm 调试它们也不包含在 createUser.php 的 POST 中,我似乎无法弄清楚为什么它们不会包含在 POST 中。关于有什么问题的任何想法?

4

2 回答 2

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

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

于 2014-01-08T07:10:57.753 回答
0

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

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

于 2013-11-20T08:23:25.840 回答