How to prevent session/cookie refresh in laravel?

Member

by shyann , in category: PHP Frameworks , 5 months ago

How to prevent session/cookie refresh in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 5 months ago

@shyann 

To prevent session or cookie refresh in Laravel, you can follow these steps:

  1. Update the config/session.php file in your Laravel project.
  2. Set the value of the lifetime option to a higher value, such as 120 minutes, to extend the session timeout.
  3. Set the value of the expire_on_close option to false to prevent the session from expiring when the browser is closed.
  4. Set the value of the same_site option to 'none' to allow cross-site cookies for session persistence.


Here is an example of how the updated session configuration might look like:

1
2
3
4
5
6
return [
    // ...
    'lifetime' => 120,
    'expire_on_close' => false,
    'same_site' => 'none',
];


  1. Additionally, you can also set the HttpOnly flag to false in the config/session.php file to allow JavaScript access to the session cookie. However, this is not recommended for security reasons.
1
2
3
4
return [
    // ...
    'http_only' => false,
];


By adjusting these session configuration options, you can prevent the session or cookie from refreshing and maintain persistent sessions in Laravel.