2

I run multiple websites from a single laravel app. Is it possible to have different session lifetimes for them?

E.g. one site should have the standard 2 hours and another should be 1 year

Chris
  • 11,108
  • 21
  • 70
  • 137
  • Looking through the source it seems it reads the config directly... So I'd be interested to see what people can come up with on this one – Chris Mar 20 '18 at 11:35
  • Possible duplicate of [Laravel: share session data over multiple domains](https://stackoverflow.com/questions/26821648/laravel-share-session-data-over-multiple-domains) – Adam Kozlowski Mar 20 '18 at 12:52
  • check also: https://laracasts.com/discuss/channels/laravel/share-session-from-multiple-domains-but-on-same-server – Adam Kozlowski Mar 20 '18 at 12:52
  • @AdamKozlowski I do not want to share session between domains. I just want to have different session lifetime values for the different domains – Chris Mar 20 '18 at 13:16

1 Answers1

0

You can set a variable for each domain in the .env file:

SESSION_LIFE_TIME=160

and call this variable in your config file:

'lifetime' => env('SESSION_LIFE_TIME', 120),

Hope this works for you.

Mahmoud Abdelsattar
  • 885
  • 1
  • 9
  • 24
  • unfortunately the domain is determined dynamically. i.e. it is not known beforehand and therefore I cannot use env variables. I would need a way that allows me to set it on the fly with an if condition – Chris Mar 20 '18 at 14:47
  • Did you try to create a helper function like `function getSessionPerDomain(){ switch ($domain){ case ('domain1'): return 120; // .. etc. } }` and call it directly in the config ? – Mahmoud Abdelsattar Mar 20 '18 at 14:59