I am using CI. I want to share session over subdomains And I'm using database to store sessions
I've tried this
ini_set('session.cookie_domain', substr($_SERVER['SERVER_NAME'],strpos($_SERVER['SERVER_NAME'],"."),100));
if(session_id ==''){session_start();}
That means x.y.com and z.y.com will use common session help me, pls
I am assuming that this above would go into the login file that processes the login and starts the session?
I have the code below in my log in file. Yes, I am a cut and paste coder :)
Does this mean it should work across subdomains since it says it's persistent sessions?
Considering the fact that you already know your domain name, is there a reason why you use substr to determine it? You could would be much more readable if you just used:
For cookies to work across multiple subdomains, the cookie domain must start with a dot (.) followed by the common part of all the sub-domains (most likely domain.tld.)
Also, the second line of your post, the one where you check if the session needs to be started is wrong. You're missing a set of parentheses after session_id because it's a function and not a constant. The conditional statement (if) would always fail causing session_start() to be called every time.
Set a new session.name before changing other session settings and starting a new session. See Notes Below:
This has consistently worked for me. The php.net documentation on this is minimal, but, it appears to be the consensus with many in the community.