'Laravel reuse session on subdomain

Let's say, I created 2 server and 4 sub domains.

  • example.com and first.example.com route to first server.
  • second.example.com and third.example.com route to second server.

2 server connect to 2 different database.

The sessions are stored in database.

If I change SESSION_DOMAIN in .env to .example.com and login to first server from example.com, the session is reused in first.example.com, too. However, I can't login to second server second.example.com, it seems to also reused session from first server.

How do I reuse session for some specific subdomain only? I'm using PHP with laravel.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source