Codeigniter会话结束后我关闭浏览器如何记住复选框

时间:2015-11-26 08:35:52

标签: php codeigniter session checkbox

Codeigniter会话在我关闭浏览器后如何记住复选框结束?

复选框已经在登录表单中,但我不知道该怎么做?

这是控制器中的登录方法

    public function login($page = 'login') {
        if (!file_exists(APPPATH. '/views/main/' .$page. '.php')) {
            // Whoops, we don't have a page for that!

            show_404();
        }
                if($this->session->userdata('is_logged_in')) {
        redirect('home');
        $this ->session ->set_flashdata('alreadysignedin', '<div class="alert alert-info"><strong>Srroy !</strong> but you are already signed in.</div>');
    } else {
        $this ->load ->library('form_validation');
        $data['title'] = ucfirst($page); // Capitalize the first letter
        $this ->load ->model('users_model');
        $this ->load ->view('include/header', $data);
        $username = $this->input->post('username');
// Get User Role 
    $this->load->model('user_profile');
    $this->user_profile->rolesdetail($username);
    $userrole = $this->user_profile->rolesdetail($username);
// Get User Role </>
        if ($this ->input ->post('login') AND $this->form_validation ->run('login') == TRUE) {
            $data = array(
                'id'             => $userrole->id,
                'username'       => $this ->input ->post('username'),
                'is_logged_in'   => TRUE,
                'roles'          => $userrole->roles,
                'email'          => $userrole->email
            );
            $this ->session ->set_userdata($data);
            $this ->session ->set_flashdata('logindone', '<div class="alert alert-success"><strong>Congratulation!</strong> you have logged in successfully.</div>');
            redirect('home');
        }
        $this ->load ->view('main/'.$page, $data);
        $this ->load ->view('include/footer', $data);
        }
    }

我读过有关cookies但我不知道它是如何工作的

1 个答案:

答案 0 :(得分:6)

很简单,在验证/处理用户凭据时提交表单后,如果找到复选框值,则在加载 cookie 帮助程序后使用$this->input->set_cookie();创建Cookie。将登录信息存储在该cookie中,当用户到达登录页面时检查该cookie,如果该cookie中存在数据,则只填充表单及其完成。您还可以加密cookie数据。 check this link for further codeigniter cookies