How to prevent session/cookie refresh in laravel?

Member

by shyann , in category: PHP Frameworks , a year ago

How to prevent session/cookie refresh in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , a year 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.

Related Threads:

How to refresh laravel cookie with vue.js?
How to test session and cookie data in PHPUnit?
How to prevent session hijacking in codeigniter?
How to prevent session hijacking in PHP?
How to check if a cookie is set in laravel?
How to set and get cookie in laravel?