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? Quote 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. Quote 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 Quote 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. Quote 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? Quote 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 Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/245508-maintianing-session-across-subdomains/#findComment-1260992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.