php - Help w/ Codeigniter session expiration time -
i dynamically set session expiration time in codeigniter. i'm autoload session class. have view contains checkbox users click (remember me). right if click check box or not expiration time stays same :/
// config.php $config['sess_expiration'] = 7200; // controller if ($this->input->post('remember_me') == 'true') { $this->session->remember_me(); } $newdata = array( 'failed_login' => 0, 'user_name' => $this->input->post('user_name'), 'logged_in' => true ); $this->session->set_userdata($newdata); // my_session.php class my_session extends ci_session { function remember_me() { $this->sess_expiration = 172800; } }
if need implement "remember me" feature - you've started in wrong way.
you need create 1 more database table fields user_id | token
.
then, after user has been logged in (with "remember me" checkbox checked on) - generate random token , insert new row current user_id , token. - set remember
cookie same token value.
now, if user enters site, not authenticated , has token - can find token , authenticate user (each token unique , strognly related specific user_id
).
Comments
Post a Comment