9

Suppose in a domain (app.domain.com) I have set a Session like this:

Session::put('test', 'value');

Then in different domain (ex. news.domain.com) I want to retrieve that session value. Note that the other domain is located ON DIFFERENT SERVER, but still same domain name.

My question is, will Session::get('test') is available in news.domain.com if I set the laravel config file to domain => '*.domain.com'?

user2002495
  • 2,126
  • 8
  • 31
  • 61

1 Answers1

24

If you have the subdomains hosted on different physical machines, setting the domain in app/config/session.php to this:

'domain' => '.domain.com'

will work as long as the two apps will be able to access a shared session data storage (for example using the database session driver and having a common database that stores the sessions).

Bogdan
  • 43,166
  • 12
  • 128
  • 129
  • 2
    and of course, they need to have the same app key right? – user2002495 Oct 20 '14 at 17:20
  • @Bogdan, you totally saved the day! I don't know if anyone else needs to know this, but the app/config/auth needs to be updated too. I had to change a web app from using the file session method to database. Could NOT figure out why they weren't looking at each other. Bah. THANKS AGAIN! – cbloss793 Jan 22 '15 at 00:34
  • What about those of us who redirect www.domain.com to domain.com? It is killing my sessions. E.g. RewriteCond %{HTTP_HOST} ^www\.domain\.com$ RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L] – zeros-and-ones May 19 '15 at 05:31