Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing session data to all subdomain codeigniter

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.

like image 292
Mohammed Sufian Avatar asked Mar 23 '14 08:03

Mohammed Sufian


1 Answers

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;
like image 134
Mohammed Sufian Avatar answered Oct 16 '22 05:10

Mohammed Sufian