How can the PHP session duration be set to last for a specific period, such as 4 hours or more?
To set the PHP session duration to last for a specific period, such as 4 hours or more, you can adjust the session cookie lifetime and the session garbage collection settings. By default, PHP sessions last until the browser is closed, but you can extend this duration by changing the session cookie lifetime and the session garbage collection settings in your PHP configuration.
// Set session cookie lifetime to 4 hours (in seconds)
ini_set('session.cookie_lifetime', 14400);
// Set session garbage collection probability to 0 to prevent automatic session expiration
ini_set('session.gc_probability', 0);
ini_set('session.gc_divisor', 1);
Keywords
Related Questions
- What are the potential benefits of using a FrontController in PHP MVC architecture?
- In what ways can PHP developers improve their understanding of basic mathematical operations and their implementation in PHP scripts for form processing?
- How can PHP beginners avoid common pitfalls when working with arrays and keys?