W3docs

PHP Sessions across subdomains

PHP sessions can be shared across subdomains by setting the session cookie's domain to the top-level domain.

PHP sessions can be shared across subdomains by setting the session cookie's domain to the parent domain. This can be done by configuring the session.cookie_domain setting before starting the session. For example, to share sessions across all subdomains of example.com, you would use:

ini_set('session.cookie_domain', '.example.com');
session_start();

It's important to note that cookies are only shared across subdomains that belong to the same parent domain. For modern security compliance, it is also recommended to set the SameSite and Secure attributes.