taith Posted August 23, 2011 Share Posted August 23, 2011 hello, im looking for a way of maintaining a single session across sub-domains... for example. domain.com shop.domain.com each starts its own session, i need a way of preserving that session across both. any thoughts? Link to comment https://forums.phpfreaks.com/topic/245508-maintianing-session-across-subdomains/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 23, 2011 Share Posted August 23, 2011 Set the session.cookie_domain to match your domain - http://us.php.net/manual/en/session.configuration.php#ini.session.cookie-domain If you follow the session_set_cookie_params link on that page, it shows how to use a leading dot on .yourdomain to match all subdomains of yourdomain. Link to comment https://forums.phpfreaks.com/topic/245508-maintianing-session-across-subdomains/#findComment-1260983 Share on other sites More sharing options...
taith Posted August 23, 2011 Author Share Posted August 23, 2011 i just tried this, and it doesnt seem to effect session cookies... $currentCookieParams = session_get_cookie_params(); session_set_cookie_params($currentCookieParams["lifetime"],$currentCookieParams["path"],'.website.com',$currentCookieParams["secure"],$currentCookieParams["httponly"]); with the real website of course. and using the root domain, or any subs, it starts a different session for each Link to comment https://forums.phpfreaks.com/topic/245508-maintianing-session-across-subdomains/#findComment-1260987 Share on other sites More sharing options...
xyph Posted August 23, 2011 Share Posted August 23, 2011 You may want to replace $currentCookieParams["path"] with just '/' I will create a sub-domain on my site and test this out. PFMaBiSmAd's solution _should_ be correct. Link to comment https://forums.phpfreaks.com/topic/245508-maintianing-session-across-subdomains/#findComment-1260988 Share on other sites More sharing options...
PFMaBiSmAd Posted August 23, 2011 Share Posted August 23, 2011 Did you put that code before every session_start statement so that it would affect all session id cookies that get created? Did you check in your browser if the session id cookie got set with .yourdomain for the Domain: value? Link to comment https://forums.phpfreaks.com/topic/245508-maintianing-session-across-subdomains/#findComment-1260989 Share on other sites More sharing options...
taith Posted August 23, 2011 Author Share Posted August 23, 2011 aaaah before session start silly me... tyvm Link to comment https://forums.phpfreaks.com/topic/245508-maintianing-session-across-subdomains/#findComment-1260990 Share on other sites More sharing options...
The Little Guy Posted August 23, 2011 Share Posted August 23, 2011 I have created the following code to do this task, it can be found here: http://phpsnips.com/snippet.php?id=62 Note: You will need to place the code in the domain, NOT in the sub-domain. Link to comment https://forums.phpfreaks.com/topic/245508-maintianing-session-across-subdomains/#findComment-1260992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.