Php ReCaptcha始终返回false,没有错误
我已经安装了ReCaptcha,配置了我的公钥和私钥,在我键入任何答案之前,一切都很好,无论答案是好是错,它甚至不会响应出现的错误 这是我的密码:Php ReCaptcha始终返回false,没有错误,php,recaptcha,Php,Recaptcha,我已经安装了ReCaptcha,配置了我的公钥和私钥,在我键入任何答案之前,一切都很好,无论答案是好是错,它甚至不会响应出现的错误 这是我的密码: require_once('recaptchalib.php'); $resp = recaptcha_check_answer ($config->privkey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_respons
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;
}
表单文件中需要有公钥,配置文件中需要有私钥:
<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
}
?>
经过几天的搜索,我找到了答案
如果有人遇到类似问题,以下是解决方案:
在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库造成的,因此最好下载最新的库:
谢谢大家。不管我的公钥是否存在于配置文件或表单文件中。。。不幸的是,你的回答没有帮助。版本1.11(当然)有新的URL。请注意,验证recaptcha_check_answer(…)总是通过http完成,而不是通过https。因此,您的私钥以明文形式发送,即使您的公钥是加密发送的。他们做出了奇怪的选择。