Should session timeout be adjusted in the php.ini file or in the session_start() function?
Session timeout can be adjusted in the php.ini file by changing the `session.gc_maxlifetime` value, which determines the maximum lifetime of a session in seconds. Alternatively, you can adjust the session timeout in the `session_start()` function by setting the `session.cookie_lifetime` parameter. Both methods achieve the same result, but adjusting it in the php.ini file will apply the changes globally to all sessions, while setting it in the `session_start()` function will only affect the current session.
// Adjusting session timeout in php.ini file
// Set session.gc_maxlifetime to desired timeout value in seconds
// Adjusting session timeout in session_start() function
session_start([
'cookie_lifetime' => 3600 // Set session timeout to 1 hour
]);
Related Questions
- Why is it recommended to use PDO or mysqli instead of mysql_* functions in PHP for database operations?
- What are the advantages of using a pre-built mailer class like PHPMailer over a custom implementation for sending emails in PHP?
- In PHP, what are the recommended methods for securely handling database credentials and sensitive information in scripts?