Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gertnaster's avatar

Multi Domain Session

Hey guys, I am not a superb developer, so i guess the problem i did run into is just to big for me.

I have a project where i have different subdomains for the language. When i login a user it is logged only for the current subdomain. So when i login at "en.project1.com" and then go to "de.project1.com" the user will not be logged in. They don't share the session. I already tried to modify the 'domain' => null, in in app/sessions.php. But when i change the value here loggin in doesn't work at all. Then everytime a new Session-row is created in the DB but I guess laravel doesn't recognize it.

is the current domain saved somehow in the session identifier? Is it possible to use one session for different domains? I found some stuff about OAuth and Single sign-on but I can not handle it by myself.

I was thinking about, when logging in and the credentials are correct, to call a script in the background via Ajax, which should log in the user for all subdomains. But I would have to do the same for logging out.. And i will probably have a lot of subdomains. The project will be several subprojects (all with the different languages) and one base page. Like this

mainproject.com

en.mainproject.com

de.mainproject.com

... Aproject.com

en.Aproject.com

de.Aproject.com

...

Bproject.com

en.Bproject.com

de.Bproject.com

So it would just feel wrong to log in the user to like 20 different pages and create 20 sessions... It would feel better to just use one session for all of them.

Okay, i hope you understand the problem and someone had the same problem and found a solution. Thanks!!!!!!!! greets. gerti

0 likes
4 replies
gertnaster's avatar

Background info.. I am using Laravel 4.2

now i just tried something, maybe it helps someone. Actually point 2 is weird for me (see below)

I display these 3 things:

Session::getId() Auth::getName() var_dump(Session::all())

I display them on "de.Aproject.com". Here I am logged in. and i display them on "en.Aproject.com"... Where I am still logged out (which I want to fix :D )

  1. The value of Session::getId() is different on both sides. Thats the problem I guess, they should share the same.
  2. The value of Auth::getName() is the same on both sides (login_82e5d2c56bdd0811318f0cf078b78bfc). Which I don't understand. Why does the second page have this value when i am not logged in?
  3. The value of Session::all() is ["login_82e5d2c56bdd0811318f0cf078b78bfc"] => string(17) "test@test.de" on the first side, on the second its empty. Thats correct.
gertnaster's avatar

Not sure if you did read at all ;) :D

Like i wrote, when i change this value the Login doesn't work at all. Then everytime i log in, a new row in the sessions table is created. But the user is still not logged in (not even for the actual domain). Also, even when it worked, I can not set a "static" domain here like ".domain.com". Because the domains will be different, like "de.P1.com", "de.P2.com", "en.P1.com", "en.P2.com". And an array is not accepted here.

bashy's avatar

No far too much to read, saw part about subdomain and went with it. Although it does link in because you can't have a cookie across multiple domains (only subdomains).

Please or to participate in this conversation.