我需要帮助让验证码工作


I need help getting recaptcha to work

我最近有一个为我设计的网站,但我的开发人员使用了一个非常糟糕的通用验证码,有一半时间失败。 我正在尝试使用验证码替换它,但是遇到了麻烦。 我无法弄清楚哪个 *.php 用于"处理",哪个用于"表单"。

我不想发布整个代码,所以这里是:

这是"表单"页面,因为它嵌入了表单字段等:http://dl.dropbox.com/u/45666699/formcode.txt

有人可以看看这段代码,告诉我应该把 recaptcha 的私人代码放在哪里吗? 另外,如何禁用已安装的"random_number"验证码? 谢谢!

您现有验证码的代码在线295, 296 and 297

require_once('recaptchalib.php');
$publickey = "6LfIUdISAAAAAKguxgdPCjZ6-OkVeu5tmcBaa7ug"; // you got this from the signup page
echo recaptcha_get_html($publickey);
好吧,

当您尝试验证是否输入了正确的验证码时(即在您处理表单提交时),您将需要私钥

通过查看您的代码应该在line 4后立即开始

使用我不久前做的一个项目,你会有这样的东西......

$recaptcha_error = NULL;
//set it to NULL initially
if(isset($_POST["btnsend"])){
    include_once(INCLUDES_FOLDER."recaptcha-php-1.11/recaptchalib.php");
    $resp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);
    if($resp->is_valid){
        //captch was gotten correctly
        //continue with your normal code processing here
    } else {
        //wrong input -- captch was invalid -- give the person the error response
        //mine is as below -- my usual way :)
        $response = array(array("Something seems to be wrong with the captcha!","Please check that you entered it correctly or check the returned error message"),false,"w");
        $recaptcha_error = $resp->error;
        //make sure to do the above so u can use it when generating the captcha display
    }
}

//You got the recaptch error (or left it as NULL above so you could do this)
//when generating your captch display as done on your lines 295, 296, 297
include_once(INCLUDES_FOLDER."recaptcha-php-1.11/recaptchalib.php");
echo recaptcha_get_html(RECAPTCHA_PUBLIC_KEY,$recaptcha_error);

希望这对(即使有点)有所帮助:)
干杯