-1

I am new to php and I am working on a web application where the requirement is that the user should be automatically logged out and returned to the login screen if there is no user activity for 10 minutes. How can I achieve this using either php or javascript?

I am currently just using session_start() in my header page.

M.Eb
  • 23
  • 1
  • 6

1 Answers1

1

try

 ini_set('session.gc_maxlifetime',54000);  
 ini_set('session.gc_probability',1);
 ini_set('session.gc_divisor',1); 

use this before calling session_start()

Or Also Try by this

Store time() in the $time variable. 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 ();
}

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

TarangP
  • 2,711
  • 5
  • 20
  • 41