how to expire php session if user is inactive for 15 mins

后端 未结 6 572
无人及你
无人及你 2020-12-04 22:48

i have created one project in PHP, into which i am managing sessions.

I am creating session in my config.php file by writing following line of code.

         


        
6条回答
  •  我在风中等你
    2020-12-04 23:21

    Store time() in the $time variable. create variable called $setTime and set the time you want user to timeout.

    After that check the condition that if $_SESSION['setTime'] is empty OR not set then store the timeout value into the session, otherwise when the page will refresh the new value will be assigned to the $_SESSION['setTime'].

    $time = time ();
        $setTime = time () + 60;
        if (empty ( $_SESSION ['setTime'] ) || !isset ( $_SESSION ['setTime'] )) {
            $_SESSION ['setTime'] = $setTime;
        }
    

    After that check that current time is more than equal to the stored time. and if it is unset the session. destroy the session as well.

    if (time () >= ( int ) $_SESSION ['setTime']) {
       session_unset ();
       session_destroy ();
    }
    

提交回复
热议问题