跨子域的Codeigniter会话
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
我有多个子域,我正在尝试跨子域使用会话。 p>
http://example.com
http://subdomain.example.com
code> pre>
我还在config中设置了cookie域。 php p>
$ config ['cookie_domain'] =“。example.com”;
code> pre>
会话用户数据 在其他域中使用时,flashdata也是空的。 我同时使用相同的会话表用于CI实例 p>
div>
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_";
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’.
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.