0

I am using session in my website to authentication of user and check if user is logged in or not.

The problem is that if user login using http://example.com and after this user open the website by using http://www.example.com, the session is not available and he has to login again.

What can I do to solve this kind of issue?

icktoofay
  • 126,289
  • 21
  • 250
  • 231
Mandeep Singh
  • 121
  • 1
  • 8

1 Answers1

1

I love how Yahoo explains it.

If your domain is www.example.org, you can host your static components on static.example.org. However, if you've already set cookies on the top-level domain example.org as opposed to www.example.org, then all the requests to static.example.org will include those cookies.

You have two options:

  1. When users go to your website, redirect to www.*
  2. Have cookies effective on the top-level domain

The issue with having cookies work everywhere is that a cookie-less sub-domain will not work on the same domain.

In this case, you can buy a whole new domain, host your static components there, and keep [that] domain cookie-free.

Community
  • 1
  • 1
Dave Chen
  • 10,887
  • 8
  • 39
  • 67