我正在尝试为我的 Codeigniter 项目设置 reCaptcha。recaptchalib.php 文件保存在views 文件夹中。
我的注册视图页面包括以下内容:
<form method="post" action="cyoa/verify.php">
<?php
require_once('recaptchalib.php');
$publickey = "correct_public_key_inserted_here";
echo recaptcha_get_html($publickey);
?>
<input type="submit" />
</form>
我的 cyoa 控制器包括以下验证功能:
public function verify()
{
require_once('views/recaptchalib.php');
$privatekey = "correct_private_key_inserted_here";
$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 {
redirect('cyoa/index');
// Your code here to handle a successful verification
}
}
我遇到的问题是页面总是重定向到 cyoa/index.html。我究竟做错了什么?