View Full Version : session sharing between pages
web242
05-09-2011, 05:24 PM
i am unable to access same session variable from different
pages (the pages are on same server)
the code works on my pc (wampserver)
but when i upload online it doesn't work
i set session veriable in one php file
and when i check using isset() in another php file it returns false
i would like to know if theres some some sort of php setting or
could anybody suggest an alternate solution.
djr33
05-09-2011, 08:22 PM
Session variables are available on any page using the same session.
Include <?php session_start(); ?> at the top of every page (it must execute before any output is sent to the browser) and it should work. But it must be on every page, not just the first one.
Sessions do expire after some time, but I don't think that's the problem here. (Usually expiration happens after 15 minutes or more of inactivity, or closing the browser.)
Note that sessions cannot be shared across different domains because sessions use a cookie to store the session ID that connects everything. There is NO way to make a session function across multiple domains.*
For the same reason, subdomains can be complicated: if you want to share a session across two subdomains you must set the cookie's domain to *.yourdomain.com
Finally, you should make sure the default cookie path is set to / and not a local directory. If you set the session cookie (and therefore a session) in /somedir/ then it won't be available in /someotherdir/. But this is not the default for PHP as far as I know because it should save the directory as / by default-- that will make it available anywhere on your site. (And *.domain.com will make it available on any subdomain.)
(*There are some very complicated work arounds but they generally do involve two separate sessions, linked together by some sort of integration between the servers such as sharing a database and remembering that the two separate sessions are connected. This is usually not required, and it's difficult to deal with when it is. I suggest avoiding it.)
web242
05-10-2011, 03:00 AM
thanks djr33 for your very informative reply
its working now!!!!!! :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.