PHP session expires ahead of time

4

I'm having a problem at a session time in PHP with CodeIgniter. I was using the sessions in CI and with so many problems I decided to look for a solution to use native sessions with the CI and at first it has improved, but still it continues to fall before the predetermined time.

In the settings I left the sess_expiration set to 7200 (default value of the CI) and whenever I do not move the system for a certain time (I have already done several tests like 10min, 30min, 1h) and almost always drops when I go refresh the page.

I played the code in Pastebin to make it easier to read.

link

And inspecting the firebug, in the Resouces-> Cookies the Expires / Max-Age is theoretically correct.

    
asked by anonymous 25.02.2014 / 15:25

3 answers

1

You have here my session function:

function sessionTimeout($time_out)//em minutos
{
    $time_out= 60*$time_out;//passa para segundos

    ini_set('session.gc-maxlifetime', $time_out);

    if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > $time_out)) 
    {
        // último pedido foi a mais de $time_out atrás
        session_unset();     // unset $_SESSION variable for the run-time
        session_destroy();   // destroy session data in storage
    }
    $_SESSION['LAST_ACTIVITY'] = time(); // atualiza a hora da última atividade

    if (!isset($_SESSION['CREATED'])) 
    {
        $_SESSION['CREATED'] = time();
    } else if (time() - $_SESSION['CREATED'] > $time_out) 
    {
        // sessão começou a mais de $time_out atrás
        session_regenerate_id(true);    // muda o ID de sessão para a atual sessão e invalida o antigo ID de sessão
        $_SESSION['CREATED'] = time();  // atualiza altura que a sessão foi criada
    }
}

Based on this answer from SOEN.

    
07.05.2014 / 13:25
0

Try to go there in the codeigniter application \ config \ config.php and change those values

$config['sess_expiration']= 0; /* nunca expirar a sessão sózinha  */
$config['sess_expire_on_close'] = TRUE; /* finalizar sessão quando o navegador for fechado */

Or you can try for .htaccess

php_value session.cookie_lifetime "99999999"

link

    
25.02.2014 / 15:31
0

Dude, I'm tired of having a problem with the CodeIgniter library session. So I developed my PHP based native Session and I never had a problem.

I opened a project in GitHub, follow the link: link

  • Only use any of CodeIgniter's library
  • Any implementation or error, just send a Pull Request or open an Issue
23.07.2014 / 00:56