-1

我有一个页面,其中包含一些我还不完全理解的 php 代码

我有一个使用 recaptcha 的 php 片段,我认为我有一个相当不错的处理。

我不确定如何将两者结合起来。

我在验证码代码中看到它触发事件,但我不确定如何在验证码完成之前阻止按钮。

现有代码是:

<div id="colOne">
<h2>Contact Us</h2>
<form action="gdform.php" method="post"> 

<table border="0" cellpadding="2" cellspacing="2" summary="feedback form" align="center">
<tbody>
<tr>
<td colspan="2">
<p>Please fill out the fields below with your information and your question
            <br />or comment and we will get back to you as soon as possible.</p>
</td>
</tr>
<tr>
<td align="left">Name:<span style="color: #ff0000;">*</span></td>
<td><input type="text" name="name" size="25" /></td>
</tr>
<tr>
<td align="left">Email Address:<span style="color: #ff0000;">*</span></td>

<td><input type="text" name="email" size="25" /></td>
</tr>
<tr>
<td align="left">Phone:</td>
<td><input type="text" name="phone" size="25" /></td>
</tr>
<tr>
<td align="left">Subject:<span style="color: #ff0000;">*</span></td>
<td><input type="text" name="subject" size="25" /></td>
</tr>
<tr>
<td colspan="2" align="left">Comments: <span style="color: #ff0000;">*</span><br /><textarea rows="20" cols="50" name="comments"></textarea></td>

</tr>
<tr>
<td colspan="2" align="center"><span style="color: #ff0000;">*</span> Required Fields</td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="Send Request" /><br /></td>
</tr>
</tbody>
</table>
</form></div>

我拥有的验证码是

编辑:这不是我的钥匙......请不要担心......不是我的钥匙,它是假的............一切都很好

<form action="" method="post">
<?php

    function sendmail()
    {
      echo "you got it";
    }

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "6LeWIAgAAAAAAPA9picBEVB18lDgGVIOIav";
$privatekey = "6LeWIAgAAAAAABViAnDjvKXxWtJGBoRaWXe";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid)
        {

                //echo "You got it!";
                sendmail();

        } 
        else 
        {
                # set the error code so that we can display it
                $error = $resp->error;
        }
}
echo recaptcha_get_html($publickey, $error);
?>
    <br/>
    <input type="submit" value="submit" />
    </form>
4

1 回答 1

1

首先,您在问题中包含了您的 reCAPTCHA 私钥,为了确保您的 CAPTCHA 安全,您应该始终保持私密性。

其次,您包含的代码是 CAPTCHA 的处理代码,而不是使其显示在您的表单中的代码。您需要将此代码放在您希望验证码显示的位置:

require_once('recaptchalib.php');
$publickey = "..."; //enter your public key here
echo recaptcha_get_html($publickey);

另一个块必须位于处理页面的顶部——根据表单的操作来判断,那就是 gdform.php:

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

if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}

当然,要使上述任何一项工作,您还必须拥有 reCAPTCHA PHP 库和您自己的公钥/私钥对。如果您没有这些,请从reCAPTCHA网站获取。

有关更多信息,请阅读reCAPTCHA PHP 快速入门

于 2009-09-08T14:25:04.633 回答