Codeigniter - Session expiration and “remember me” feature

前端 未结 3 1107
囚心锁ツ
囚心锁ツ 2020-12-29 12:36

I\'m building a \"Remember Me\" feature in Codeigniter, normally I see libraries/projects setting a cookie on the user with a token, this token gets saved in the database an

3条回答
  •  余生分开走
    2020-12-29 13:11

    The simpliest solution that I have found for this problem is to just modify the cookie created by Codeigniter by this way:

            $this->session->set_userdata('user', $user); // a cookie has been created
            if($this->input->post('remember_me'))
            {
                $this->load->helper('cookie');
                $cookie = $this->input->cookie('ci_session'); // we get the cookie
                $this->input->set_cookie('ci_session', $cookie, '35580000'); // and add one year to it's expiration
            }
    

提交回复
热议问题