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 the best practices for handling user cookies in PHP to ensure data privacy?
- What are the advantages and disadvantages of using PHP sessions for user authentication compared to other methods?
- Is the approach of calculating the check digit by subtracting from 10 and handling cases where the result is 10 or negative numbers correct?