1

Suppose I have one login form in php and I set session on user_id and user_name. Now, as per my php knowledge the default session timeout is 24mins, and suppose I'm using this application for whole day. Then obviously after each 24 mins my application will be logged out and I require to login again BUT still I'm able to use it continuously. HOW?

Dear friends don't laugh, I'm new in this.

Vilas
  • 837
  • 2
  • 15
  • 41

2 Answers2

1

The default session timeout is indeed 24 minutes. This means however that an user is going to lose his session when the user doesn't interact with the application for 24 minutes (inactivity). You can change the session timeout in php.ini, search for: session.gc_maxlifetime = 1440 (1440 seconds = 24 minutes), or directly in the php code ini_set('session.gc_maxlifetime', 1440);

Daan
  • 12,099
  • 6
  • 34
  • 51
  • it means if I logged in and then I went to take a bath for 50 mins and come to see my application then I require login again, right? – Vilas Oct 01 '15 at 07:54
1

Try this

// 24 minutes in seconds
$time= 2880;
ini_set('session.gc_maxlifetime', $time); // set the session max lifetime to 24 minutes

session_start();

if (isset($_SESSION['my_session']) && (time() - $_SESSION['my_session'] > $time))
{
    // last request was more than 24 minutes ago
    session_unset();     // unset $_SESSION variable for this page
    session_destroy();   // destroy session data
}
$_SESSION['my_session'] = time(); // Update session
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85