session time in php

3

Colleagues.

Is there any way to determine a time when the session should remain active? The reason is that I have a system from which I use sessions, but if the user stays idle for a certain period, it seems that the session is inactive, causing the user to log in again. Is there any way to inhibit this? I would not like to use cookies, as some browsers may have this functionality inactive.

    
asked by anonymous 30.09.2015 / 16:03

1 answer

2

In the login script you put:

$_SESSION["sessiontime"] = time()+360;
#caso queira um tempo mais so fazer as contas em segundos

This script places in an include that every page the user accesses calls this include.

if ( isset( $_SESSION["sessiontime"] ) ) 
            { 
                if ($_SESSION["sessiontime"] < time() ) 
                {
                    session_destroy();
                    header ("location:login.php");
                   #se session for menor que o time ele
                   #destroi a session e redireciona pra login
                } 
                else
                {
                    $_SESSION["sessiontime"] = time() + 360;
                   #se session for maior que o o time ele adiciona mais 360
                   #na sessiontime 

                }
            } 
            else
            { 
                header ("location:login.php");
                #se sessiontime tiver vazia ele ja direto pra login.php
            }
    
30.09.2015 / 16:36