CodeIgniter 3 and Sessions

I recently updated CodeIgniter 3 following this guide: CI3: Update 3.0 from 2.2.1 .

I set this configuration in the file application / config / config.php:

$config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'ci_session_my_site'; $config['sess_expiration'] = 604800; // 1 week $config['sess_save_path'] = NULL; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 300; 

Something is wrong? My session is being destroyed in a few hours ...

+6
source share
4 answers

In your save path, you need to set up a location folder. Use 'files' as your preferred session driver. As shown below, I configured the cache for storing sessions in the BASE PATH, which sets the folder. Make sure you download the automatically loaded sessions and $config['encryption_key'] = '' add the key.

You can set up database sessions, but it works just as well. Verify that the permissions on the 0700 folder

http://www.codeigniter.com/userguide3/search.html?q=session&check_keywords=yes&area=default

 $config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 1440; $config['sess_save_path'] = BASEPATH . 'yourfoldername/cache/'; $config['sess_match_ip'] = TRUE; $config['sess_time_to_update'] = 300; 

Once this is done, you will be able to do something like.

 $this->load->library('session'); $data_session_set = array('logged' => 1, 'username' => $this->input->post('username'), 'user_id' => $this->user_auth->get_id()); $this->session->set_userdata($data_session_set); 
+10
source

In the /config/config.php application, set this value:

 $config['sess_save_path'] = sys_get_temp_dir(); 
+1
source

I use this code that it works.

  if (version_compare(PHP_VERSION, '5.4.0', '<')) { if(session_id() == '') session_start(); } else { if (session_status() == PHP_SESSION_NONE) session_start(); } 
0
source

I used 2 different values ​​and somehow they worked, it depends on the version of Centos:

For Centos 6.X, I used:

In the /config/config.php application, set this value:

$ config ['sess_save_path'] = NULL;

For Centos 7.X, I used:

$ config ['sess_save_path'] = sys_get_temp_dir ();

it will not work if you move the application from one version of the server to another without editing this value.

0
source

Source: https://habr.com/ru/post/982144/


All Articles