What are the best practices for managing session lifetime in PHP?

To manage session lifetime in PHP, it is important to set the session cookie lifetime and the session garbage collection probability appropriately. This helps in controlling how long a session remains active and when it should be considered expired.

// Set session cookie lifetime to 1 hour
ini_set('session.cookie_lifetime', 3600);

// Set session garbage collection probability to 1%
ini_set('session.gc_probability', 1);