After login in this url www.example.com
, if I remove the www
extension from address-bar the login detail value doesnot keep by session.

- 576
- 1
- 10
- 19

- 1
- 4
-
2You might want to read up on cookie domains. – GordonM May 02 '12 at 08:59
-
in login code there is no-error. i want to know if i remove the www from addressbar like(example.com) after login, it's does not keep the seesion values why it's happen? plz clear to me!!!!!!! – tamildinesh May 02 '12 at 09:03
4 Answers
Try creating a redirect function from non-www to www. See this topic: WWW to non-WWW Redirect with PHP
put this in your globals, or in your includes file, or just add it before any session_start()
call.
ini_set("session.cookie_domain",".example.com");
another option would be to to add this:
php_value session.cookie_domain .example.com
to your .htaccess

- 5,089
- 6
- 33
- 47
-
thanks man, but i want to set one cookie value for both example.com and www.example.com. if i add or remove the www from address it will be stay with same cookies, what i am do for that!!!!!!!!!!!!!!! – tamildinesh May 02 '12 at 09:15
-
@tamildinesh yes, the code above will do exactly what you want.. just try it. I've also added one more option for you – Adi May 02 '12 at 11:26
Your session is maintained by a cookie. When you log on to www.example.com, a cookie is saved for this domain by default, which is represented with every request to a URL in this domain. example.com is a different cookie domain, and the cookie won't therefore be presented.
Solutions are to either redirect from example.com to www.example.com as Andrei suggested, or to make the cookie domain match as Adnan suggests - both valid answers.

- 71,481
- 13
- 158
- 186
Try clearing browser cache deleting temporary files and prefetch files clear dns from cmd ipconfig/flushdns
re open browser login, writing or removing www should not alter with session since it runs on server.
make sure you are not Re - Starting session.

- 1
- 1