2012-01-14 157 views
3

我已经安装了ReCaptcha,配置了我的公钥和私钥,一切都很好,直到我输入任何答案,无论它是好还是错,它都不是回应发生的错误。ReCaptcha总是返回false,没有错误

这里是我的代码:

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

if (!$resp->is_valid) { 
    echo $resp->error; 
} 

回答

5

我已经找到了答案搜索的天后......

下面是如果有人有类似的问题解决方案:

在你rechaptchalib.php变化:

define("RECAPTCHA_API_SERVER", "http://api.recaptcha.net"); 
define("RECAPTCHA_API_SECURE_SERVER", "https://api-secure.recaptcha.net"); 
define("RECAPTCHA_VERIFY_SERVER", gethostbyname('api-verify.recaptcha.net')); 

要:

define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api"); 
define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api"); 
define("RECAPTCHA_VERIFY_SERVER", "www.google.com"); 

这可能是由于过时PHP库,因此这将是更好地为您也可以下载最新的磁带库:

http://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest

谢谢大家。

+0

是的。版本1.11(肯定)有新的URL。 – 2014-06-25 17:40:04

+0

请注意验证** recaptcha_check_answer(...)**总是通过** http **完成,并且永远不会** HTTPS **。因此,即使您的公钥以加密方式发送,您的私钥也会以明文形式发送。奇怪的选择。 – 2014-06-25 17:41:59

0

你需要有公钥表单文件&在配置文件中的私钥:

<html> 
<body> <!-- the body tag is required or the CAPTCHA may not show on some browsers --> 
    <!-- your HTML content --> 

    <form method="post" action="verify.php"> 
    <?php 
     require_once('recaptchalib.php'); 
     $publickey = "your_public_key"; // you got this from the signup page 
     echo recaptcha_get_html($publickey); 
    ?> 
    <input type="submit" /> 
    </form> 

    <!-- more of your HTML content --> 
</body> 
</html> 

这是你的文件格式要求去的地方:

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

    if (!$resp->is_valid) { 
    // What happens when the CAPTCHA was entered incorrectly 
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . 
    "(reCAPTCHA said: " . $resp->error . ")"); 
    } else { 
    // Your code here to handle a successful verification 
    } 
    ?> 

如需进一步的帮助,你可以去:http://code.google.com/apis/recaptcha/docs/php.html

+0

这就是说,无论我的公钥是在配置文件还是表单文件中......不幸的是,您的回答没有帮助。 – Cyclone 2012-01-15 21:31:42