Php zend_验证码始终失败isValid()
我遇到了一个问题,Php zend_验证码始终失败isValid(),php,zend-framework,captcha,Php,Zend Framework,Captcha,我遇到了一个问题,Zend_Captcha在提交页面并且调用Captcha的isValid()方法时总是返回false。这让我抓狂,因为就我而言,这应该行得通 我首先在控制器的action函数顶部声明它 $captcha = new Zend_Captcha_Image('captcha', array( 'captcha' => array( 'name' => 'graduatesignupcaptcha',
Zend_Captcha
在提交页面并且调用Captcha的isValid()
方法时总是返回false。这让我抓狂,因为就我而言,这应该行得通
我首先在控制器的action函数顶部声明它
$captcha = new Zend_Captcha_Image('captcha',
array(
'captcha' => array(
'name' => 'graduatesignupcaptcha',
'wordlen' => 6,
'font' => $this->config->captcha->font,
'imgDir' => $baseUrl.'/images/captcha/',
'imgUrl' => $this->config->webserver->name.'/images/captcha/',
)
)
);
$captcha->setHeight(80)
->setTimeout(300);
我做常规的表单验证,所有的工作都正常,但是当我来验证输入到表单中的验证码值时,它总是返回false
//next we check the captcha text to ensure that the form is a person not a script
$captchaText = $form->getElement('captchainput')->getValue();
$captchaId = $form->getElement('captchaid')->getValue();
//$captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_'.$captchaId);
$captchaArray = array(
'id' => $captchaId,
'input' => $captchaText
);
if(!$captcha->isValid($captchaArray)){
$log->log(implode(",",$captcha->getErrors()), Zend_Log::DEBUG);
$form->getElement('captchainput')->setErrors(array('messages' => 'Bad security code'));
$formFailed = true;
}
我已经检查以确保我获取的id和作为隐藏元素存储在表单中的id与正在生成的图像匹配,但无论我做什么,这总是失败的
我是不是错过了一些简单的东西??还是有更好的方法来处理这个问题
谢谢,这可能与会话有关-可能会话值没有正确存储。检查
$\u会话中的内容
-应该是:
["__ZF"]=>
array(1) {
["Zend_Form_Captcha_ef828f68e467db99e8f358244ad6c667"]=>
array(2) {
["ENNH"]=>
int(1)
["ENT"]=>
int(1260764250)
}
}
["Zend_Form_Captcha_ef828f68e467db99e8f358244ad6c667"]=>
array(1) {
["word"]=>
string(6) "fubara"
}
[“_ZF”]=>
阵列(1){
[“Zend\u Form\u Captcha\u ef828f68e467db99e8f358244ad6c667”]=>
阵列(2){
[“嗯”]=>
int(1)
[“ENT”]=>
内部(1260764250)
}
}
[“Zend\u Form\u Captcha\u ef828f68e467db99e8f358244ad6c667”]=>
阵列(1){
[“单词”]=>
字符串(6)“fubara”
}
请注意,在您的代码中,您可能从新captcha中获取$captchaId,但在会话中,您可能仍然拥有旧captcha的ID。验证ID是否确实匹配
如果您没有,请检查您的会话是否正常工作,如果它们正常工作,则可能是某些错误-向ZF问题跟踪程序提交错误 这对我很管用
Zend_Loader::loadClass('Zend_Session_Namespace');
$sessionNamespace = new Zend_Session_Namespace('cptc');
Zend_Loader::loadClass('Zend_Captcha_Image');
$captcha = new Zend_Captcha_Image();
$captchaArray = array(
'id' => $sessionNamespace->code,
'input' => $filter->filter($this->_request->getParam('captcha'))
);
if ($captcha->isValid($captchaArray)) {
//your action here
}
谢谢,$captchaId有问题,使用上面的帮助我找到了问题。谢谢