开发者

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

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]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜