开发者

Cookies not sent to server when logged in through a subdomain

I have a website www.example.com When a user logs in when he visits http://example.com and then when he 开发者_开发技巧browses http://www.example.com, he is shown as NOT logged in. I think the reason is that the cookies set when he visited http://example are not being sent to the server when the same user visits http://www.example.com

I want the user to be shown as logged in in both of the sites if he logs in any one of the sites. I have a mobile site also http://m.example.com. I want the user to be shown as logged in here also.

I am using PHP and Zend Framework for my web application.


Try setting the cookie domain (5th arg of set_cookie) to ".example.com".

http://php.net/set_cookie

The domain that the cookie is available to. To make the cookie available on all subdomains of example.com (including example.com itself) then you'd set it to '.example.com'. Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included. Setting the domain to 'www.example.com' or '.www.example.com' will make the cookie only available in the www subdomain.

Hope this helps!


set it in php.ini

 session.cookie_domain = .example.com 

OR

ini_set("session.cookie_domain", ".example.com"); 

This will alive session in sub domain also.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜