Use secure session management
Laravel provides a secure way to manage user sessions using encrypted cookies. You can configure session encryption in the config/session.php file. Additionally, you should configure session timeouts to ensure that inactive sessions are automatically destroyed after a specified period of time.
How to configure session?
-
Open the config/session.php file in your Laravel application.
-
Set the driver option to the desired session driver. The default is encrypt, but you can also use file, database, redis, or other drivers.
-
Set the lifetime option to the number of minutes you want a session to last before it expires. The default is 120 minutes (2 hours). For example, to set the session lifetime to 30 minutes, you would add the following line to the config/session.php file:
'lifetime' => 30,
- If you are using the encrypt session driver, make sure that the key option is set to the application’s encryption key. You can generate a new encryption key by running the php artisan key command in your application’s root directory.
'encrypt' => true,
'key' => env('APP_KEY'),
- Save the config/session.php file.