1
votes

I'm trying to save my session, it expired after refreshing the page.

In my controller:

 if($u_id){
                $data=  array(
                    'id'=>$u_id['id'],
                    'user_name'=>$u_id['user_name'],
                    'password'=>$password,

                );

                $this->session->set_userdata('logged_in',$data);
                $this->session->set_flashdata('login_succeed','Logged in Successfully');
                redirect('home/homepage');
            }

And in my homepage view:

if (isset($this->session->userdata['logged_in'])){
                        echo $this->session->userdata['logged_in']['user_name'];}

My config:

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

First time when redirect me to homepage, the session is correct and it gave me the username perfectly, but when I refresh the page, the session expired and redirect me to login page. Should I do something in construct or what can I do? please help! I'm using codeigniter

1
Is there an error on the view?Elymentree
@Elymentree No it is working first time I signed in, but when I refresh the page the session expired and redirect me to login page again.Yazan Mehrez

1 Answers

0
votes

You have not set your save path. I put mine in cache but you can choose where you want it.

$config['sess_save_path'] = APPPATH . 'cache/sessions/';

Or you can use FCPATH

$config['sess_save_path'] = FCPATH . 'application/cache/sessions/';

Set the sessions folder permissions to 0700