How can the time of session expiration be stored in PHP when no script is being executed at that time?
To store the time of session expiration in PHP when no script is being executed, you can set a session variable with the expiration time when the session is created or updated. This way, the expiration time will be stored in the session data and can be accessed even when no script is actively running.
// Set session expiration time when session is created or updated
$_SESSION['expiration_time'] = time() + (30 * 60); // 30 minutes from now
// Check session expiration time in subsequent scripts
if(isset($_SESSION['expiration_time']) && time() > $_SESSION['expiration_time']) {
// Session has expired, perform logout or other necessary actions
}
Related Questions
- What are some recommended database design strategies for efficiently storing and retrieving multiple file names associated with a single entity in PHP?
- How can PHP be used to extract and save specific content, such as images and messages, from an RSS feed as a PNG file?
- What is the significance of error_reporting and error_log functions in PHP debugging?