1//Ending a php session after 30 minutes of inactivity
2$minutesBeforeSessionExpire=30;
3if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > ($minutesBeforeSessionExpire*60))) {
4 session_unset(); // unset $_SESSION
5 session_destroy(); // destroy session data
6}
7$_SESSION['LAST_ACTIVITY'] = time(); // update last activity
1//Expire session after 10 seconds
2ini_set('session.gc_maxlifetime', 10);
3
4//Set the probability and divisor to be set to 100% of probability
5ini_set('session.gc_probability', 1);
6ini_set('session.gc_divisor', 1);
7
8session_start();