What is the difference between session.gc_maxlifetime and session.cookie_lifetime in PHP session settings?
The difference between `session.gc_maxlifetime` and `session.cookie_lifetime` in PHP session settings is that `session.gc_maxlifetime` specifies the maximum lifetime of a session in seconds, after which the session data may be considered garbage and cleaned up by the garbage collection process, while `session.cookie_lifetime` specifies the lifetime of the cookie in seconds which is used to identify the session. To ensure that sessions expire after a certain time, you should set both `session.gc_maxlifetime` and `session.cookie_lifetime` to the same value.
// Set the maximum lifetime of the session data to 1 hour (3600 seconds)
ini_set('session.gc_maxlifetime', 3600);
// Set the lifetime of the cookie to 1 hour (3600 seconds)
ini_set('session.cookie_lifetime', 3600);
// Start the session
session_start();
Keywords
Related Questions
- What are some alternative approaches to using hidden fields in PHP forms for handling file content display?
- What potential errors or pitfalls should be considered when working with fsockopen in PHP for UDP connections?
- Are there any best practices or recommended approaches for integrating Outlook with PHP for a local intranet application?