0

Hi Everyone,

I got a strange problem with session. Session variables that I define in a page with "www" prefix in the domain name for example http://www.foo.com/page1.php for some reason can't be recognized in page2.php if I remove the "www". But if I use "www" like http://www.foo.com/page2.php, it works just fine.

Can anybody tell me why is this happening? I sure use session_start(). Does anybody in any chance have experienced this?

Using php 5.2.8 on LiteSpeed host.

Any help will be greatly appreciated.

-Max

5
Contributors
10
Replies
13
Views
7 Years
Discussion Span
Last Post by mayureshgoyal
0

This is not strange at all.
Those are two different domains, and sessions stick to one domain for security.

With cookies you can choose domains they will work on, so I'm sure you can look up in the PHP manual for sessions on how to get around having sessions for your second domain too.

0

This is not strange at all. Those are two different domains

Hello, thanks for your reply. But I'm confused. Does removing the "www" makes it a different domain? Say for example, is http://www.google.com different from http://google.com? I thought they're just the same.

looking forward to your response.

- Max

1

Yes it is a different domain - setup to show the same content though.

In DNS it is usually setup like this
my.domain.com A 000.000.000
www.my.domain.com CNAME my.domain.com

Unless you use virtual servers in Apache, theres not much more to it.

But in all correctness, it is different domains.
WWW. prefix is nothing special, just some old guy who thought the world would be better if we put www. in front of everything ;)

0

Technically my problem is not solved yet. But thanks for clearing that up for me. All this time I thought they're the same. I really appreciate your replies. It really helped me.

0

I guess PHP has an option to automatically share sessions with www. domains aswell - are you using a non-default PHP.ini?
In DNS www. is just as much a subdomain as sub. would be :)

Edited by Excizted: n/a

0

I haven't actually checked.
But if i don't specify www as a sub-domain it autimatically views the original domain without any re-directs

0

Some websystems enforces www. to be left in or left out.
By checking if the request uri has www., and if not will redirect to it.

This would be a hotfix to your problems, and has no, afaik, sideeffects.

0

you can set session to work for all subdomain by using ini_set for 'session.cookie_domain'

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.