phpsycho Posted July 29, 2011 Share Posted July 29, 2011 I was wondering how to allow php sessions to be held and used across all sub domains securely? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/243219-php-sessions-across-subdomains/ Share on other sites More sharing options...
Eiolon Posted July 29, 2011 Share Posted July 29, 2011 Typically, a sub domain is just another directory in the your domains root (ie. domain.com/sub). It's just DNS settings that make it accessible with the directory name infront of the domain (ie. sub.domain.com) So with that in mind, handle sessions as you normally would. Use session_start(); at the top of each page you are passing it to, and if in a shared hosting environment, consider storing session information in a database. Quote Link to comment https://forums.phpfreaks.com/topic/243219-php-sessions-across-subdomains/#findComment-1249151 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2011 Share Posted July 29, 2011 See the domain parameter at this link - http://www.php.net/manual/en/function.session-set-cookie-params.php Quote Link to comment https://forums.phpfreaks.com/topic/243219-php-sessions-across-subdomains/#findComment-1249214 Share on other sites More sharing options...
phpsycho Posted July 29, 2011 Author Share Posted July 29, 2011 Okay so using this: session_set_cookie_params(0, '/', '.example.com'); session_start(); Would do the trick? and thats secure, correct? I'm confused with the "set_cookie".. is that setting a cookie to your browser with session data in it? If so.. that can't be very secure I would imagine.. Secure: If TRUE cookie will only be sent over secure connections. can you define "secure connection"? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/243219-php-sessions-across-subdomains/#findComment-1249221 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2011 Share Posted July 29, 2011 The session cookie is the session ID cookie, that carries the session id. A secure connection refers to a HTTPS connection. Quote Link to comment https://forums.phpfreaks.com/topic/243219-php-sessions-across-subdomains/#findComment-1249224 Share on other sites More sharing options...
phpsycho Posted July 29, 2011 Author Share Posted July 29, 2011 ah alright, so just the id of the session, no other data. Feeling better about this lol. Instead of using that code I posted, does setting this option: session.cookie_domain = .mydomain.com in the php.ini file gunna do the same? Because it seems much more simpler to just do it that way. Quote Link to comment https://forums.phpfreaks.com/topic/243219-php-sessions-across-subdomains/#findComment-1249230 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2011 Share Posted July 29, 2011 Yes, you can put settings in the php.ini to avoid needing to add lines of code to set them in each individual script. Quote Link to comment https://forums.phpfreaks.com/topic/243219-php-sessions-across-subdomains/#findComment-1249236 Share on other sites More sharing options...
phpsycho Posted July 29, 2011 Author Share Posted July 29, 2011 Okay great! Thanks very much! Quote Link to comment https://forums.phpfreaks.com/topic/243219-php-sessions-across-subdomains/#findComment-1249238 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.