我已经多次尝试但是重新开始仍然没有工作,总是说Undefined index:recaptcha_challenge_field
但我遵循了指示...
Hare是我的编码...我使用yii框架
在PHP中:
<?php
<form id="registration" method="post" action="<?php echo Yii::app()->getHomeUrl(); ?>?r=Register/Registration">
//some input detail
//at the bottom the recaptcha code
<?php
require_once('captcha/recaptchalib.php');
$publickey = "the_public_key"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
</form>
?>
那么在控制器中
public function actionRegistration(){
require_once('captcha/recaptchalib.php');
$privatekey = "the_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 {
echo "Your code here to handle a successful verification";
}
}
有任何建议让它在这个yii项目中运作吗?
答案 0 :(得分:0)
$_POST
变量可能没有您要查找的内容。
当您遇到此类问题时,最好的办法是致电var_dump()
,查看 被添加到$_POST
的内容,例如:
require_once('captcha/recaptchalib.php');
$privatekey = "the_private_key";
//var dump for debugging:
echo '<pre>';
var_dump($_POST);
echo '</pre>';
exit;
//now the rest of your code, as before:
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);