2

If I login through website.com and then type www.website.com, it doesn't show that I am login in and I have to do that again. What's the problem?

good_evening
  • 21,085
  • 65
  • 193
  • 298
  • Problem is that website.com and www.website.com are not the same domains, therefore you need to set your session_id cookie to be allowed at www.website.com too. – N.B. May 24 '11 at 19:12
  • 1
    Check the session cookie established when you visit `website.com`. If there's no leading `.`, then it applies ONLY to website.com and not any 'sub' version, such as the `www.` one. – Marc B May 24 '11 at 19:12

2 Answers2

3

This is normal. Session cookies apply to the exact domain they were issued by default. www.website.com is a different domain from website.com.

You can expand the scope of the cookie to sub-domains, but the much better way is to actually have only either www.website.com or website.com, and to redirect one to the other.

For redirecting www to non-www, see

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
3

This should fix it:

session_set_cookie_params(
  60 * 24,        // 24 minutes lifetime
  '/',            // path
  '.website.com', // any subdomain of website.com
  false,          // SSL not required
  true            // not accessible by JavaScript
);

session_start();
Matthew
  • 47,584
  • 11
  • 86
  • 98