Reputation: 2943
I have been losing my session variables rather consistently when I click on the link from our websites notification email. After breaking my head for a long time on this, I today realized that www.domain-name.com does not contain the session variables while domain-name.com does!!
Why does this happen? And what do I do to set things right(php-apache)?
Upvotes: 4
Views: 1162
Reputation: 16
How to redirect with .htaccess file:
http://papermashup.com/useful-htaccess-techniques/
http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/#red2
Upvotes: 0
Reputation: 7935
The session ID is stored in a cookie, and in the cookie can be specified how it should react over domain names.
Take a look at PHP's setcookie documentation.
You can change PHP's session cookie configuration with:
ini_set("session.cookie_domain", ".mydomain.com");
Upvotes: 2
Reputation: 887275
Sessions are based on cookies, which are per-domain.
www.domain.com
is a different domain than domain.com
, so their cookies are kept separate.
Standard practice is to choose one variant and 301
redirect the other variant to the preferred one.
Upvotes: 3
Reputation: 32279
There's nothing technically special about ‘www’. The domain ‘domain.com’ is distinct from ‘www.domain.com’; if you want to associate them, that needs to be explicit somewhere, usually in the HTTP server configuration.
Upvotes: 1