session lasting 30 minutes

3

I have a login system in PHP. I save the user's login and password in a session.

Start it as follows:

// Inicia a sessão
session_start();

My question and how to do this session has a duration of 30 minutes, ie if the user leaves the page stopped for 30 minutes the session has to be deleted.

    
asked by anonymous 06.10.2016 / 16:07

2 answers

2

You can use session_set_cookie_params to "set" a lifetime for the session

$time = strtotime('+30 minutes', 0);
session_set_cookie_params($time);
session_start();
    
06.10.2016 / 16:48
0

See if this helps you:

session_start();

    if (isset($_SESSION['atividade']) && (time() - $_SESSION['atividade'] > 1800)) {

                session_unset();
                session_destroy();
            }
    $_SESSION['atividade'] = time();
    
06.10.2016 / 21:01