老是提示验证码错误
本帖最后由 linger308 于 2009-6-19 10:04 编辑使用CI自带的SESSION 验证验证码程序。
获取验证函数为:
function captcha(){
$this->load->library('CaptchaImage');
ob_start();
$this->session->set_flashdata('captcha', $this->captchaimage->getString());
$this->captchaimage->setFont('./system/fonts/type-ra.ttf',16);
$this->captchaimage->draw();
ob_flush();
}
function code_check($str){
if($str==$this->session->flashdata("captcha")){
return TRUE;
}else{
$this->validation->set_message('code_check', '%s不正确');
return FALSE;
}
}
最近有网站用户反映输入验证码提示错误,认真分析了一下客户机系统时间和服务器系统时间不一致时就会COOKIE过期,时区不一致更会过期,$this->session->flashdata("captcha") 获取的值为空,提示验证码错误,请问有什么有什么好的办法解决没? 别用 cookie 的 session 了,换 KNDB Session 还用KNDB Session 两天了,在用户注册完也使用SESSION 的注销,但数据表中的数据还是与日剧增,有没办法用户使用完,表中的数据自动销毁呢 给login控制器增加个自动删除超期session的SQL 我用的1.7.1版自带的验证码插件,没出现报错呀.
function captcha()
{
$this->load->plugin('captcha');
$vals = array(
'word' => '',
'img_path' => './images/',
'img_url' => 'http://localhost/images/',
'font_path' => base_url().'system/fonts/texb.ttf',
'img_width' => '80',
'img_height' => 30,
'expiration' => 1
);
$cap = create_captcha($vals);
$this->session->set_userdata('code',$cap['word']);
return $cap;
}
视图: echo $cap['image'];
验证就粗略写下:
$this->form_validation->set_rules('code','验证码','callback_checkCode');
function checkCode($code)
{
if ($code==$this->session->userdata('code'))
{
return true;
}
else
{
$this->form_validation->set_message('checkCode', '%s输入错误');
return FALSE;
}
} 感谢楼上,总算解决了CI自身验证码的问题。:victory:
页:
[1]