I want use session in my website but I can't find best way to store them, codeigniter offers files , database and so on. but which is best??
I use file with this config:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = '_s';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 0;
$config['sess_regenerate_destroy'] = FALSE;
but i get this error:
Unable to create file ./_s\ci_sessionecc1dccdd1118e02ee956dde8aadaf7f1116c1ac because No such file or directory
I must use database ??
I find the best way is to create a cache/session/ folder in your systems directory is more safer I put important things like logs and cache in system rather than application folder.
http://www.codeigniter.com/user_guide/libraries/sessions.html
Config.php
$config['encryption_key'] = 'somekey';
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = BASEPATH . 'cache/sessions/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
I also would autoload sessions my self
application/config/autoload.php
$autoload['libraries'] = array('database', 'session');
Usage Example
On login form_validation success part
$data = array(
'is_logged' => true,
'username' => $this->input->post('username')
);
$this->session->set_userdata($data);
One you set your data then after login can get sessions $this->session->userdata('username')
etc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.