How to use session variables for multiple subdomains?

I lose my session variables quite consistently when I click on the link to our email address. After a long break in my head, today I realized that www.domain-name.com does not contain session variables, and domainnamename does !!

Why is this happening? And what should I do to install correctly (php-apache)?

+4
source share
4 answers

Sessions are based on cookies that are for the domain.
www.domain.com is a different domain than domain.com , so their cookies are stored separately.

The standard practice is to choose one option and 301 redirect another option to the preferred one.

+3
source

The session identifier is stored in a cookie, and the cookie may indicate how it should respond to domain names.

Take a look at the PHP setcookie documentation.

You can modify the PHP session cookie configuration with:

 ini_set("session.cookie_domain", ".mydomain.com"); 
+2
source

There is nothing technically special regarding www. The domain.com domain is different from www.domain.com; if you want to bind them, it should be explicitly somewhere, usually in the HTTP server configuration.

+1
source

All Articles