0

I want to expire PHP session after 3 hours of user inactivity. Therefore I am using following code.

ini_set('session.gc_maxlifetime', '10800');
ini_set('session.cookie_lifetime', '10800');

But I can't see it is working as expected. It is expiring the session after 3 hours whether I am actively using the application. I want to achieve this from the application. Not from the php.ini file.

How can I use PHP session to expire and Sign Out the user from the application after 3 hours of user inactivity ?

Thanks in advance

WP Learner
  • 788
  • 1
  • 13
  • 34
  • 2
    Possible duplicate of [How do I expire a PHP session after 30 minutes?](https://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes) – Zac Webb Jun 01 '17 at 11:18

1 Answers1

0

You can do something like that in php:

<?php
 session_start();
 $duration = (DURATION * 60);

 if(isset($_SESSION['started']))
 {

 $showform = 0;
 $time = ($duration - (time() - $_SESSION['started']));
 if($time <= 0)
 {
    unset($_SESSION['count']);
    unset($_SESSION['offender']);
    $showform == 1;
 }
 }
 else
 {
 $_SESSION['started'] = time();
 }
?>

Set the time duration and unset it after the duration expires. Replace Duration text with minutes count like 3 hours = 180 minutes so put 180 there.

Shahroze Nawaz
  • 589
  • 5
  • 9