Search code examples
phpsubdomainsession-cookies

PHP: Share session on some subdomains, but not all


I have 1 domain and 2 subdomains, lets say:

domain.com
a.domain.com
b.domain.com

I would like for domain.com and the a.domain.com to share their PHP session, but for b.domain.com to have a session of its own.

How can I approach this with PHP's ini_set('session.cookie_domain', ...) ?

All I can find online is

ini_set('session.cookie_domain', '.domain.com')

But this applies to all subdomains...

Thank you!


Solution

  • For anyone who needs it, it turns out the solution for this was naming my sessions. I stored the name of the session on my .env file:

    session_name($_ENV['SESSION_NAME']);
    session_start();