5

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

wdphd
  • 905
  • 6
  • 15
  • 25

3 Answers3

4

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_";
Community
  • 1
  • 1
wdphd
  • 905
  • 6
  • 15
  • 25
  • I don't see how you gleaned that from the other post. Also, the other post uses now-deprecated CodeIgniter settings. Any explanation as to why this solves the problem? – S. Imp Jan 23 '18 at 20:43
  • @S.Imp Second time I saw a comment from you complaining about deprecated settings and missing explanation. Why not add an answer with correct settings and more explanation? FYI, many stuff still uses the older CI, in which these settings are still used. – Brainfeeder Mar 19 '18 at 09:39
0

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’.

Vanjor
  • 181
  • 1
  • 6
0

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.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Draconid
  • 36
  • 2