PHP - make session expire after X minutes

前端 未结 2 1364
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 12:42

i am using the following technique...

From the login.php the form posts to the page check.php where i do this



        
2条回答
  •  难免孤独
    2020-12-15 13:04

    Store a timestamp in the session:

     0)
    {
        $array = mysql_fetch_assoc($result);    
    
        session_start();
        $_SESSION['user_id'] = $uzer;
        $_SESSION['login_time'] = time();
        header("Location:loggedin.php");            
    }
    else
    {
        header("Location:login.php");
    }
    ?>
    

    Check if the timestamp is within the allowed time window (600 seconds is 10 minutes):

     600)
    {
        header("Location:login.php");
    }
    else
    {
        // uncomment the next line to refresh the session, so it will expire after ten minutes of inactivity, and not 10 minutes after login
        //$_SESSION['login_time'] = time();
        echo ( "this session is ". $_SESSION['user_id'] );
        //show rest of the page and all
    }
    ?>
    

提交回复
热议问题