Extend PHP session using . htaccess

Asked

Viewed 206 times

3

How to extend a session in PHP using . htaccess?

I used this code below:

php_value session.cookie_lifetime 28800
php_value session.cache_expire 28800
php_value session.gc_maxlifetime 28800

However I believe that it has not worked, alias, has to check if the session I started is with this expiration time?

What would be the default session (cookie) expiration time?

I believe that the *.cache_expire code chunk has nothing to do with the session, I can remove from the code?

  • 1

    i found this example https://stackoverflow.com/questions/6075770/php-session-timeout, which is more or less like yours, according to the guy, you should add only php_value Session.cookie_lifetime 18000 and php_lifetime value Session.gc_max18000. About the default cookie time I don’t know how to answer.

1 answer

1

// Faz o set de duracao em segundos
ini_set('session.gc_maxlifetime', 3600);

// Seta o cookie em segundos
session_set_cookie_params(3600);    

/*
     * Pagina de login
     */
    if($login){
        $_SESSION['CREATED'] = time();
    }

    /*
     * Funcao para verificar o tempo da session
     */
    if (time() - $_SESSION['CREATED'] > 1800) { // Tempo em segundos

        session_regenerate_id(true);    // Regenera o id da session para prevenir o session fixation
        $_SESSION['CREATED'] = time();  // Atualiza o tempo da session
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.