php session time

Asked

Viewed 724 times

3

Colleagues.

Is there any way to determine a time when the session should remain active? The reason is that I have a system of which I use sessions, but if the user remains inactive 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 wouldn’t like to use cookies as some browsers may have this feature down.

  • I think it has to do with cookies so I would have to change the time in cookies

  • Yes, by the configuration file php.ini. But you want to leave with how much time ? Forever ?

  • you can limit yes I see the answer I have a method I use for this msm

  • 1

    Read on in this discussion soen.

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 I put in a include that every page the user accesses it 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
            }
  • Thank you all. Thalles Daniel’s reply helped me.

Browser other questions tagged

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