Managing PHP sessions

if(session_id() == '') {

session_start();

}

if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1400)) {

// last request was more than 30 minutes ago

session_unset(); // unset $_SESSION variable for the run-time

session_destroy(); // destroy session data in storage

session_start();

}

$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp