Best way to store a session in an encoder

I want to use a session on my website, but I cannot find a better way to store them, codeigniter offers files, a database and so on. but best of all?

I am using a file with this configuration:

$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 

Should I use a database?

+5
source share
1 answer

I believe that the best way to create a cache / session / folder in your system directory is more secure. I put important things, such as logs and cache in the system, and not in the 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 will also autoload sessions myself

application /Config/autoload.php

$autoload['libraries'] = array('database', 'session');

Usage example

Upon successful login form_validation

 $data = array( 'is_logged' => true, 'username' => $this->input->post('username') ); $this->session->set_userdata($data); 

One of them you set your data after the login can receive the sessions $this->session->userdata('username') , etc.

+2
source

All Articles