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();
Related Questions
- What are the advantages of using htmlspecialchars() function in PHP output?
- What are the key differences between using copy() and ftp_put() functions for file transfer in PHP?
- How can developers ensure that the output of htmlspecialchars() is properly displayed in the browser, especially when dealing with special characters like "&" or "><"?