Rejoanul Alam Rejoanul Alam - 6 months ago 40
PHP Question

Access subdomain session from main domain

I have an application in mydomain.com. I want user will be redirected to example.mydomain.com when login to mydomain.com, however session successfully generating in a directory at example.mydomain.com. Now my problem is after submit login, users are not able to login example.mydomain.com. Although there are session files are available.

Session driver is file (mydoman.com config file)

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'mydir/application/session_data';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 0;
$config['sess_regenerate_destroy'] = FALSE;


My application working fine in local server. But not working in production.

Answer

You also have to set the cookie_domain and cookie prefix in your config file like this

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