Codeigniter increase session time out not working

2019-02-20 23:06发布

问题:

I am new to codeigniter framework. I have a problem with session time out with pages. Right now I had enabled with the ip match ,user agent matching but doesn't work. One more way I had tried with updated the 2.1.4 libraries files and copied into my systems folders but this is also not worked.

Please help me to solve the session time out problem.the following code I had used in config->config.php.

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

I need to increase the session time out time but now i need to check the session time out is working or not.if this 10 seconds session time is working then i can able to increase the session time.

Thanks in advance please help me.

回答1:

Finally i found the solution for the problem.

The following ways to increase or decrease the session time out. 1.

  ini_set('session.gc_maxlifetime', 60);

  config->config.php

  $config['sess_expiration'] = ''; //in seconds.

2.

 $config['sess_time_to_update'] = '' ;//in seconds (as same in sess_expiration seconds)

3.If you are checking in login controller and all controller for the session data as

$_SESSION['data'] == 'your login id or role or something

.this is not getting session expired the session datas.but we need to check the check with $this->session-> userdata('your id or data need to check') and before once login successfull then need to assign the value to the session as $this->session->set_userdata('your id or something');

while checking the session = $this->session->userdata() is empty or zero need to session_destory() and then need to redirect to your home page. Another way to increase :

  1. If your site was running in apache2 and only one website means we can directly mention the session_gc_maxtime.

These two ways i had tried and i found the solution for the session time out.its working fine for me.

Thanks to all.



回答2:

if you dont have ci_sessions table in your database, create it using the following script.

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
    session_id varchar(40) DEFAULT '0' NOT NULL,
    ip_address varchar(16) DEFAULT '0' NOT NULL,
    user_agent varchar(120) NOT NULL,
    last_activity int(10) unsigned DEFAULT 0 NOT NULL,
    user_data text NOT NULL,
    PRIMARY KEY (session_id),
    KEY `last_activity_idx` (`last_activity`)
);

use $this->session->set_userdata($array); to get session data. Then it should work properly