I have been facing this issue since yesterday and yet I could not resolve this. Issue is sessions are not working in local environment but when for a testing purpose I put the same files on a live server, they work all okay.
Here if my config.php file:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
Here is how I save the data in one of my model files
$this->session->set_userdata('user',$result); //$result works fine, it produces
right result
In my view, I tried to access this by:
$this->session->userdata['user']['name']; //name here is an element in result array
I get this error:
Severity: Notice
Message: Undefined index: user
Filename: home/home.php
Line Number: 2
To my surprise, this same code runs without any error on server.
Also, to be able to know the data being saved by Codeigniter sessions, I tried database method.
I changed the code to below in config.php file
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_sessions';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
Instead of inserting one row of data, it inserts four. Please see below screenshot from the database (last four rows).
Can anybody point to the error? Any help will be appreciated.