使用ajax验证重新计算的错误

时间:2011-07-26 18:42:33

标签: php recaptcha

我正在尝试使用ajax验证recaptcha,我面临的唯一问题是它总是使得recapthca输入错误!即使我做对了! 我真的好奇我的代码出了什么问题!

<?php
    require_once('recaptcha/recaptchalib.php');
    define("PUBLICKEY"," ");
    define("PRIVATEKEY"," ");

    $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
    if ($resp->is_valid) {
    ?>success<?
        $name = $_POST['name'];
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $reason = $_POST['reason'];
        $header = 'From: ' . $email . " \r\n";
        $msg = "Sent from: " . $name . "\r\n";
        $msg .= "Email: " . $email . " \r\n";
        $msg .= "Phone: " . $phone . " \r\n";
        $msg .= "Contact reason:" . $reason . " \r\n";
        $msg .= "Message: " . $_POST['message'] . " \r\n";
        $msg .= "Date and time " . date('d/m/Y', time());

        $to = '';
        $subject = 'contact page';

        mail($to, $subject, utf8_decode($msg), $header);
    }
    else 
    {
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
    }
?>
表格页面上的

我有这个

<?php 
    require_once('recaptcha/recaptchalib.php');
    define("PUBLICKEY","");
    define("PRIVATEKEY"," ");
?>

<div id="contact-form">
<?php echo  $content; ?>
        <form action="#" method="POST" id="contactForm" onSubmit="return validateCaptcha()">
    <div class="form">
            <label for="name">Your Name: <span class="requireds">(Required)</span><br /></label>
            <input id="name" name="name" class="text-input" minlength="2" />
   </div>
   <div class="form">
            <label for="email">Your Email:<span class="requireds">(Required)</span><br /></label>
            <input id="email" name="email" class=" text-input" />
   </div>
   <div class="form">
            <label for="phone">Your Phone:<br /></label>
            <input id="phone" name="phone" type="text"  maxlength="200" class="text-input"  />
   </div>
   <div class="form">
            <label  for="reason">Contact reason:<br /></label>
            <select id="reason" name="reason" class="select">
                <option>Sales question </option>
                <option>Time/ Delivery</option>
                <option>My existing Order</option>
                <option>Technical Question</option>
                <option>Revision/ Support</option>
                <option>Other</option>

            </select>
   </div>
   <div class="form">
            <label for="message">Message: <span class="requireds">(Required)</span> <br /></label>
             <textarea id="message" name="message" class="textarea"></textarea>
   </div>

   <div style="margin:10px 0; width:495px;  -moz-border-radius:3px; border-radius:3px;">
                <p style="color: #f14444; text-align:right; font-size:12px" id="captchaStatus">&nbsp;</p>
                    <?php echo recaptcha_get_html(PUBLICKEY); ?>

      </div>
       <input type="submit"  value="" class="send"/>

    </form> 

我已经检查过公钥和私钥是否正确.. 有人知道这段代码有什么问题吗?

1 个答案:

答案 0 :(得分:0)

提交recaptcha时收到此错误,告知我您的API密钥未正确提交:

  

要使用reCAPTCHA,您必须从https://www.google.com/recaptcha/admin/create

获取API密钥

<强>更新

recaptcha_check_answer ($privatekey,

看那里的问题?您使用的是$privatekey而不是PRIVATEKEY,因此您实际上并未将任何内容作为私钥提交。错误是正确的(相信错误消息!)。我使用Chrome的内置开发人员工具(Ctrl + Shift + i)来调试它。