Errant_Shadow Posted October 30, 2009 Share Posted October 30, 2009 I need to make a session that will stay active across all of my sub domains, but so far all I can make is a session that works only on the sub domain it was created on. Link to comment https://forums.phpfreaks.com/topic/179569-solved-global-sessions/ Share on other sites More sharing options...
Errant_Shadow Posted October 30, 2009 Author Share Posted October 30, 2009 Well, I've found a few methods to do this... The php.ini configuration contains a line that, by default, is blank; your server fills this in with your full domain name when a session is created. Unfortunately, that includes the subdomain, thus limiting that session to ONLY that subdomain. To fix this you can either open the php.ini and change it to read as: "session.cookie_domain = .yourdomain.com" (the dot separator there at the beginning is important for cross-browser compatibility) Or, if you can't, or don't want to access the php.ini file, you can use the ini_set method to do pretty much the same thing: ini_set('session.cookie_domain', substr($_SERVER['SERVER_NAME'],strpos($_SERVER['SERVER_NAME'],"."),100)); And this can be included in an init file that should be included in every page; or it can be included by itself and it appears to run fine. Alternatively, you can use the session_set_cookie_params() method before every call to session_start(). The parameters available include int $lifetime [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]. The brackets mean that in order to set the domain, you must first set the life time and the path (in that order); keeping in mind that the default life time is zero (0) and the default path is "/". So this method would read: session_set_cookie_params(0, "/", ".yourdomain.com") Link to comment https://forums.phpfreaks.com/topic/179569-solved-global-sessions/#findComment-947562 Share on other sites More sharing options...
Errant_Shadow Posted October 30, 2009 Author Share Posted October 30, 2009 Now, while that solved the question here (thus solving the thread) it did not fix my problem... So if anyone would like to continue helping me to find a solution to my rather persistent bug, I've made a new thread: The Indestructable Session Link to comment https://forums.phpfreaks.com/topic/179569-solved-global-sessions/#findComment-947566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.