0

I have this scenario where I have 4 websites built with Laravel 6 and all of them resides on same server and all of them are subdomains e.g.

https://account.mywebsite.com

https://business.mywebsite.com

https://realestate.mywebsite.com

https://deals.mywebsite.com

the issue is in https://account.mywebsite.com, if I'm authenticated there already, the rest of the Laravel websites must be also authenticated so simply a single sign in mechanism. What I'm thinking right now, If I can access the authentication session or cookie from the account website (https://account.mywebsite.com), or from the account subdomain set a custom auth cookie/session then the rest of the Laravel websites access that auth cookie/session then I can authenticate the rest of the Laravel websites. I believe, each Laravel store unique session and cookie.

Session::put('key', 'value');
Cookie::get('name');

so any ideas, help on how to access a cookie or session from other Laravel app that is also on same server?

Juliver Galleto
  • 8,831
  • 27
  • 86
  • 164
  • 1
    It wasn't easier to create a single web app and use the [sub domain routing](https://laravel.com/docs/6.x/routing#route-group-sub-domain-routing) feature? – IlGala Oct 02 '19 at 10:15
  • This will help you : https://stackoverflow.com/questions/9153716/sharing-session-variables-between-multiple-subdomains – Yasin Patel Oct 02 '19 at 10:18
  • https://stackoverflow.com/questions/644920/allow-php-sessions-to-carry-over-to-subdomains – Yasin Patel Oct 02 '19 at 10:18

1 Answers1

0

The easiest way would be to change the domain of the cookies to the root domain (without the subdomain). That way all subdomains will have access to them.

Set the SESSION_DOMAIN setting in your .env file:

SESSION_DOMAIN=mywebsite.com

Note: Laravel uses the APP_NAME for the session cookie name, so if your Laravel installations have different APP_NAMEs they will not share the same session. If you want them to share the same session you can manually set the SESSION_COOKIE.

Thomas
  • 8,426
  • 1
  • 25
  • 49