|  | 
 
 发表于 2012-7-5 10:19:28
|
显示全部楼层 
| 楼主 验证码已经显示出来了 但是不会验证啊~ 
 怎么验证呢
 
 控制器
 
 PHP复制代码 复制代码function yzm(){
 $conf['name']='yzm'; //作为配置参数
 $this->load->library('captcha_code',$conf);
 $this->captcha_code->show();
 $yzm_session=$this->session->userdata('yzm');//将验证码放在了缓存中
 }
 
 视图
 
 HTML复制代码 复制代码<img id='code_img' onclick='this.src=this.src+"/"+Math.random()' src='<?php echo site_url('admin/login/yzm')?>'><br /><a href="javascript:document.getElementById('code_img').src='<?php echo site_url('admin/login/yzm')."/"?> '+Math.random();void(0);">单击更换验证码</a>
 控制器
 
 PHP复制代码 复制代码 
function do_post()
                {
                        $username = $this->input->post('username',true);
                        $password = $this->input->post('password',true);
                        $code = $this->input->post('code');
                        
                        if($username && $password)
                        {
                                if($code == $this->session->userdata('yzm '))
                                {
                                        $admin = $this->user_mdl->get_full_user_by_username( $username );
                                        if($admin)
                                        {
                                                if( $admin->password == md5($password) )
                                                {
                                                        $this->session->set_userdata('uid',$admin->uid);
                                                        $this->session->set_userdata('username',$admin->username);
                                                        
                                                        $id = $admin->uid;
                                                        $data['lastlogip'] = $this->session->userdata('ip_address');
                                                        $data['lastlogtime'] =  now();
                                                        $this->user_mdl->edit_user($id,$data);
                                                        
                                                        
                                                        $this-> _message('登录成功','admin/index',true);
                                                }
                                                else
                                                {
                                                        $this-> _message('密码不正确','admin/login/index',true);
                                                }
                                        }
                                        else
                                        {
                                                $this-> _message('不存在的用户','admin/login/index',true);
                                        }
                                }
                                else
                                {
                                        $this-> _message('验证码不正确!','admin/login/index',true);
                                }
                        }
                        else
                        {
                                $this-> _message('用户名、密码、验证码不能为空','admin/login/index',true);
                        }
                        
                }
 | 
 |