我需要帮助让recaptcha工作

时间:2012-06-05 14:53:54

标签: php security captcha

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

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

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

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

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

当您尝试验证输入了正确的补丁时(即处理表单提交时),您需要私钥

通过查看代码,应该在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);

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