1
votes

Im using the Session Library of Codeigniter on my Website connected to a MySQL Database. I have my own Library that works with the session wich is created to handel the login check.

Basically when i log in i store that i'm logged in, in the userdata from the session cookie. (then there are other checks to have some sort of security)

$this->session->set_userdata('logged_in','1');

Now as soon as the session id gets refreshed (standard 300 seconds) all my userdata is gone. I cheked in the Database and there the session Id is not getting updated it just creates a new one.

I'm using the Codeigniter 3.0 and im not sure if thats supposed to work like that.

Edit:

my config.php (session stuff)

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

cookie Stuff

$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

Basically what happens ist the following thing:

I get the Session with the id 123. I assign the userdata logged_in = 1 to the session. All is saved in the DB. After 5 minutes. (Or the Time defined in the config file)

$config['sess_time_to_update'] = 300;

I get in my Browser a new session with the id 137 without the userdata. The Session 123 with the userdata logged_ind = 1 is still in the database, together with the newly created session 137.

So instead of an update "sess_time_to_update" its more creation of a new session.

1
can you provide your session settings found in config.php ?CodeGodie
Check out the value of your sess_expiration value in your application/config/config.php fileSolarBear
According to here : codeigniter.com/userguide3/libraries/… "If a sessions cookie does not exist (or if it doesn’t match one stored on the server or has expired) a new session will be created and saved." So if there is a problem with the cookie, it is supposed to a new session instead of updating. If you just want to change expiration, follow the lead of @SolarBear. However, I suggest you to code your own session class if you need something specific.Süha Boncukçu
@CodeGodie i edited the post. Süha Boncukçu thats right but the session id still exist in the db (i double checked that, so why does it create a new one?)Teifun2

1 Answers

0
votes

your session keeps expiring, change these settings:

From:

$config['sess_expiration'] = 0;

To:

$config['sess_expiration'] = 7200; // expires in 2 hours