How can session data be stored for a longer period of time in PHP?

By default, PHP session data is stored on the server and lasts only until the browser is closed or the session expires. To store session data for a longer period of time, you can increase the session cookie lifetime in the php.ini file or set it programmatically using the session_set_cookie_params function.

// Increase session cookie lifetime to 1 week (604800 seconds)
ini_set('session.cookie_lifetime', 604800);

// Start the session
session_start();