How can the lifetime of sessions be set in PHP without using cookies?

When using sessions in PHP, the lifetime of sessions can be set by changing the session.gc_maxlifetime directive in the php.ini file. This directive controls the maximum lifetime of a session in seconds before it is considered expired and cleaned up by the garbage collector. By adjusting this value, you can control how long sessions persist without relying on cookies.

// Set the maximum session lifetime to 1 hour (3600 seconds)
ini_set('session.gc_maxlifetime', 3600);

// Start the session
session_start();