How can session variables be properly managed to ensure they expire after a certain period of inactivity in PHP?
Session variables can be properly managed to expire after a certain period of inactivity by setting the session.gc_maxlifetime variable in the php.ini file to the desired session timeout value. Additionally, you can update the session cookie expiration time using session_set_cookie_params() function in PHP.
// Set session timeout to 30 minutes
ini_set('session.gc_maxlifetime', 1800);
// Update session cookie expiration time
session_set_cookie_params(1800);
// Start the session
session_start();
Keywords
Related Questions
- What are some best practices for handling string manipulation in PHP to ensure accurate results?
- What are the best practices for targeting elements in a CSS file?
- How can PHP developers efficiently handle dynamic column configurations for different user groups, such as friends, family, and acquaintances?