zivklen
zivklen

Reputation: 79

How to change the PHPSESSID cookie domain?

I have 2 subdomains sub1.domain.com and sub2.domain.com

sub1 is the one to set the login session but the session was not shared because they have different cookie domain

sub1's cookie domain => .sub1.domain.com

sub2's cookie domain => .sub2.domain.com

Option 1: to change sub2's .sub2.domain.com into .sub1.domain.com so that they can share session

Option 2: to change sub1's .sub1.domain.com to .domain.com

I would want the option 1 because we're trying to avoid changes on sub1.domain.com and domain.com as possible.

I have tried this codes on sub2's end but no luck

ini_set('session.cookie_domain', '.sub1.domain.com');
session_set_cookie_params (0,'/','.sub1.domain.com');

Upvotes: 1

Views: 3163

Answers (1)

Kevin Borders
Kevin Borders

Reputation: 2992

You cannot set session.cookie_domain to a different subdomain, but you can set it to .domain.com and it will be visible on all subdomains:

ini_set('session.cookie_domain', '.domain.com');

Upvotes: 3

Related Questions