Codeigniter sessions across sub domains

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

I have multiple subdomains and i'm trying to use the sessions across subdomains.

http://example.com http://subdomain.example.com

I have also set the cookie domain in config.php

$config['cookie_domain'] = ".example.com";

The session userdata and also flashdata are empty when used in the other domain. Im using the same session table as well for both CI instance

回答1:

From the following solution : Sharing sessions

Both the cookie_domain and cookie prefix has to be set

$config['cookie_domain'] = ".example.com"; $config['cookie_prefix'] = "example_";


回答2:

first floor is right ,but does not clearly the reason

Reasons: from: https://ellislab.com/forums/viewthread/131851/#651233

CI’s session, like any other session mechanism, uses a cookie to identify the session. It’s is the cookie that should be available cross-domain.

For domain, you need to specify ‘.domain.com’, not ‘*.domain.com’.



回答3:

Only $config['cookie_domain'] part is required, $config['cookie_prefix'] is only to make things clean or you have some sub domain uses same domain but does not wanted to be shared.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!