Sharing session data to all subdomain codeigniter

随声附和 提交于 2019-12-01 03:44:03

问题


I am trying to use one session data for all of my subdomains.

I have created a subdomain in cpanel like this : *.mydomain.in

and my *.mydomain.in uses the same path as my mydomain.in example:

mydomain.in uses path on my server: /public_html/mydomain.in

*.mydomain.in uses path on my server: /public_html/mydomain.in

Now the problem is every time I visit the site it's creating a different session. For example:

I visit mydomain.in .... it creates a session.

I visit example.mydomain.in .... it creates a different session

I again visit mydomain.in ... it creates a different session.

my codeigniter config file:

$config['encryption_key'] = 'MY-SECRET-KEY-HERE';

$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

$config['cookie_prefix'] = "";
$config['cookie_domain'] = ".mydomain.in";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;

Any help or suggestion would be a great help. Thanks in advance.


回答1:


Here's how I solved the issue.

 $config['sess_cookie_name'] = 'ci_session';
 $config['sess_expiration'] = 0;
 $config['sess_expire_on_close'] = TRUE;
 $config['sess_encrypt_cookie'] = TRUE;
 $config['sess_use_database'] = TRUE;
 $config['sess_table_name'] = 'ci_sessions';
 $config['sess_match_ip'] = TRUE;
 $config['sess_match_useragent'] = FALSE;
 $config['sess_time_to_update'] = 300000000;


 $config['cookie_prefix'] = "etc_anything_";
 $config['cookie_domain'] = ".mydomain.in";
 $config['cookie_path'] = "/";
 $config['cookie_secure'] = FALSE;


来源:https://stackoverflow.com/questions/22588700/sharing-session-data-to-all-subdomain-codeigniter

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