1
votes

My sessions in Codeigniter are timing out in less time than I specified in the "config/constants.php" file. I set that constant to 3600 seconds (one hour) but sometimes I get kicked out in 5 or 10 minutes. This happens in regular MVC calls, no ajax involved.

I'm trying to access the last_activity value in the CI session, but this is what the CI documentation currently states: "last_activity: Depends on the storage, no straightforward way. Sorry!"

So how can I access that value? Any ideas?

Here's some additional info:

    `$config['sess_driver'] = 'files';
    $config['sess_cookie_name'] = 'ci_session';
    $config['sess_expiration'] = EXPIRE_SESSION;
    $config['sess_save_path'] = sys_get_temp_dir();
    $config['sess_match_ip'] = FALSE;
    $config['sess_time_to_update'] = 86400;
    $config['sess_regenerate_destroy'] = FALSE;'
1
I am not sure, but may be you can't get your constant value here in config.php, please try once with hard-coded value : 3600 - kishor10d
Not sure what this is sys_get_temp_dir() but save path some thing like APPPATH . 'cache/sessions/'; - Mr. ED
@kishor10d: Thanks for the reply. Executing "print '<pre>' . print_r($this->config, TRUE) . '</pre>';" tells me that I can in fact use constants in "config.php". Using the value "3600" or "EXPIRE_SESSION" (which is also 3600) is exactly the same. - Pedro Araujo Jorge
@wolfgang1983: The function sys_get_temp_dir does just what it says, it outputs your system's temporary files directory. In my case it's "C:\Users\pedro\AppData\Local\Temp" and that location does have a lot of files and folders so it looks like it's working. - Pedro Araujo Jorge
@PedroAraujoJorge I would not use that my self I would use a folder in application directory somewhere. - Mr. ED

1 Answers

0
votes

If you're using the default session handling scheme, the last activity is the timestamp "column", or whatever it looks like in the session file. Should update every time you refresh a page. It may not update when you do something like access a modal or manipulate the page via AJAX, I haven't checked.

Here's what it looks like from the manual as a database insert:

CREATE TABLE IF NOT EXISTS `ci_sessions` (
        `id` varchar(128) NOT NULL,
        `ip_address` varchar(45) NOT NULL,
        `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
        `data` blob NOT NULL,
        KEY `ci_sessions_timestamp` (`timestamp`)
);