使用php将验证码添加到此web按钮

使用php将验证码添加到此web按钮,php,captcha,Php,Captcha,我有一个包含一些php代码的页面,我还没有完全理解 我有一个使用recaptcha的php代码段,我认为我有一个相当不错的处理方法 我还不知道如何将两者结合起来 我在验证码中看到了它触发事件的地方,但我不确定在验证码完成之前如何阻止按钮 现行守则如下: <div id="colOne"> <h2>Contact Us</h2> <form action="gdform.php" method="post"> <table border="

我有一个包含一些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>



首先,您的问题中包含了您的reCAPTCHA私钥,为了保证验证码的安全,您应该始终保持私钥

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

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密钥可能不是一个好主意如果您要-1我,您至少应该说明原因,以便我可以尝试修复它