PHP Session is treating as different domain, after adding a 'www.' infront of webpage
if i am setting a session in http://example.com/path/file1.php
then can't getting it in http://www.example.com/path/file2.php but getting the value in http://example.com/path/file2.php
- the 开发者_运维知识库"www." is creating the issue.
Is that a bug?
no, thats intended behaviour.
"" is treated as another subdomain than "www" (or other ones, if you have more subdomains), and so it's saved in a different cookie (per default, a cookies validity is per domain).
to avoid this, you could simply redirect users that enter from http://example.com/path/file1.php (or anything else with "example.com") to http://www.example.com/path/file1.php (or anything else with "www.example.com")
You can share the session cookie across all subdomains if you call session_set_cookie_params with a value of ".example.com" (notice the leading dot) in the domain parameter,
To make the cookie available on all subdomains of example.com (including example.com itself) then you'd set the domain parameter in setcookie() method to '.example.com'
[src here]
精彩评论