EchoFool Posted March 21, 2010 Share Posted March 21, 2010 If i set a session on my main domain.com will that same session still work under a domain like www.subdomain.domain.com ? Because at the moment my script doesn't appear to like it - has any one managed to achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/ Share on other sites More sharing options...
TeddyKiller Posted March 21, 2010 Share Posted March 21, 2010 I haven't tried it but I'm assuming it'll be like that because it is infact a different domain. However.. I could be wrong. Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029415 Share on other sites More sharing options...
EchoFool Posted March 21, 2010 Author Share Posted March 21, 2010 Hmm that would be a pain if your correct as that would mean my idea can't work Wanted one session to work across all my subdomains Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029416 Share on other sites More sharing options...
Ruzzas Posted March 21, 2010 Share Posted March 21, 2010 i think they disabled it for a reason. so hackers cant hack lol Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029419 Share on other sites More sharing options...
EchoFool Posted March 21, 2010 Author Share Posted March 21, 2010 uhh what ? Why would that add to hacking? Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029420 Share on other sites More sharing options...
TeddyKiller Posted March 21, 2010 Share Posted March 21, 2010 Shared servers are very high to hacking with sessions unless having your own session folder. Other than that, I don't know of any reasons. Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029421 Share on other sites More sharing options...
greatstar00 Posted March 21, 2010 Share Posted March 21, 2010 use mysql session then create a mysql table, named sessin when someone open a session, store to the mysql database (set timestamp) when certain time, clean the sessions then u can achieve it across domain, even across server session choose a mysql server that u can connect use a ip, or domain Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029423 Share on other sites More sharing options...
PFMaBiSmAd Posted March 21, 2010 Share Posted March 21, 2010 None of that is necessary. If you A) read the session handling section of the php.net documentation - http://us2.php.net/manual/en/book.session.php (i.e. you are trying to incorporate sessions into your script, you must read the documentation for what you are doing to be affective at doing it) you will B) find that there is a session.cookie_domain setting that will allow the session cookie to match all sub-domains/host-names of your domain. Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029493 Share on other sites More sharing options...
EchoFool Posted March 21, 2010 Author Share Posted March 21, 2010 So where do i put the session.cookie_domain to set it to my domain ? On every page? Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029600 Share on other sites More sharing options...
EchoFool Posted March 21, 2010 Author Share Posted March 21, 2010 I put this: session_set_cookie_params(0, '/', '.edited-out.com'); session_start(); Didn't do anything though =/ The handling section just said~: To implement database storage, or any other storage method, you will need to use session_set_save_handler() to create a set of user-level storage functions. Don't see how that helped at all. Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029606 Share on other sites More sharing options...
EchoFool Posted March 21, 2010 Author Share Posted March 21, 2010 Okay i tried this aswell in my php.ini file: <?php // The domain for which the cookie is valid. session.cookie_domain = .edited-out.com ?> still not working, user logs in on main domain then when they go to subdomain the session is not set anymore even though i still have session start =/ Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029631 Share on other sites More sharing options...
PFMaBiSmAd Posted March 21, 2010 Share Posted March 21, 2010 Based on what you have stated you are doing, setting the session.cookie_domain (as long as it is being set the same before every session_start()) should work. What have you done to troubleshoot what it is doing? Are full php error_reporting/display_errors on so that you would know if the session is starting without errors (i.e. would sessions work at all in both pieces of code even without changing sub-domains)? Is the session cookie being sent to your browser and is the value in the session cookie the the same that session_id() shows that php is using on each page? Show us the two different URL's you are using. xxxxx out any sensitive information but don't change any of the other parts of the whole urls that you are using. Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029634 Share on other sites More sharing options...
EchoFool Posted March 21, 2010 Author Share Posted March 21, 2010 Well here it is, in more detail: www.xxxxxx.com/login.php this script has: <?php session_start(); ?> Before i edited the php.ini i had: <?php session_set_cookie_params(0, '/', '.edited-out.com'); session_start(); ?> And when user logged in successfully $_SESSION['Current_User'] = $UserID; (lets say 1) Now a user clicks a link which takes them to www.test.xxxxxx.com/index.php This has: <?php session_start(); ?> Before i edited the php.ini i had: <?php session_set_cookie_params(0, '/', '.edited-out.com'); session_start(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029638 Share on other sites More sharing options...
EchoFool Posted March 21, 2010 Author Share Posted March 21, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029732 Share on other sites More sharing options...
EchoFool Posted March 21, 2010 Author Share Posted March 21, 2010 bump again Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029795 Share on other sites More sharing options...
DavidAM Posted March 22, 2010 Share Posted March 22, 2010 No offense intended, but did you actually use 'edited-out.com' or did you use 'yourdomain.com'? If your main url is www.MyDomain.com and your sub-domain is www.test.MyDomain.com, then I think the setting would be: session_set_cookie_params(0, '/', '.MyDomain.com'); I've never used this, but I want to make sure you set the right value. Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1029810 Share on other sites More sharing options...
EchoFool Posted March 22, 2010 Author Share Posted March 22, 2010 I used my real domain, the edited - out .com was just for posting purposes as so i don't have my site posted in the forum Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1030044 Share on other sites More sharing options...
EchoFool Posted March 22, 2010 Author Share Posted March 22, 2010 I forgot to ask - should there be a full stop before he "mydomain.com" ? Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1030080 Share on other sites More sharing options...
TeddyKiller Posted March 22, 2010 Share Posted March 22, 2010 Try it with, and without and see which way works. Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1030104 Share on other sites More sharing options...
EchoFool Posted March 22, 2010 Author Share Posted March 22, 2010 Nope still doesn't work either way Quote Link to comment https://forums.phpfreaks.com/topic/195975-sessions-with-subdomain/#findComment-1030108 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.