Session ID changes in CodeIgniter

I use the CodeIgniter session function and I run this code:

$session_id = $this->session->userdata('session_id'); echo "My Session ID is $session_id"; 

And it changes every time the page loads. Does this mean that sessions are not being saved properly? Is there any way to debug this and find out why? Or am I not using this library correctly?

I get no errors when turning on error reporting, and I use the CI autoload ability to load the session library:

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

Any advice will help thanks!

Example code output above:

My Session ID: 7c92bac53d2654df6e87eb4e4cb25467

.. reboot ..

My session id is c6dd14aed2499760f788a1364dcab030

UPDATE: Session configurations inside config.php look like this:

 $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_expire_on_close'] = FALSE; $config['sess_encrypt_cookie'] = FALSE; $config['sess_use_database'] = FALSE; $config['sess_table_name'] = 'ci_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = TRUE; $config['sess_time_to_update'] = 300; 

So, I found that

 session_start(); $_SESSION['myvar']='var'; 

also doesnโ€™t store anything, something seems to be wrong in the session store on my Linux server.

My session save path has apache: apache 775 permissions. Perhaps this needs to be ported to serverfault?

+6
source share
6 answers

According to CI Session.php, the identifier changes with every update, but they retain a link to the old identifier so that they can update the right line.

In addition, according to the document: "session_id" is restored (by default) every five minutes. "

Is there a reason you need to access session_id? If you need some kind of fixed identifier, you must create your own "my_session_id" so it will not change between requests.

 $uniqueId = uniqid($this->CI->input->ip_address(), TRUE); $this->session->set_userdata("my_session_id", md5($uniqueId)); 
+14
source

@ this.lau

You might mention that a file link would be useful for beginners.

i.e. CodeIgniter/system/libraries/Session.php

+1
source

Replacing the directory system / libraries / session with the latest version (from the CI website) will solve the problem. There were several errors in the CI session libraries, and they are already resolved.

+1
source

A possible problem that you can describe here: https://github.com/EllisLab/CodeIgniter/issues/3108

The thing is as stupid as it can be. If you set the name of the cookie with dots, it will restore the session ID every time you reload the page. And, of course, you will not be able to store user-specific data!

0
source

If you do not want to update the session every five minutes, make the following changes.

go to session.php file in System / libraries / Session.php and set all parameters like public $ sess_encrypt_cookie; public $ sess_use_database; ... for spaces This works for me

0
source

Changing session_id is normal in CI. But I had a problem. Session values โ€‹โ€‹were not saved, and not stored only in CI.

I fixed it by updating Codeigniter to the latest version, which is currently 3.1.6.

0
source

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


All Articles