webfeet Posted May 21, 2008 Share Posted May 21, 2008 I am trying to set a session variable in one directory, and access it from another within the same web site. It appears that session variables are specific to the directory in which they are created, although I cannot find this stated explicitly in the documentation. Is there a way to get around this? :-\ I don't know if it's relevant, but my php.ini file has session.save_path = /tmp session.cookie_path = / session.cookie_domain = Link to comment https://forums.phpfreaks.com/topic/106663-access-session-variables-from-a-different-directory/ Share on other sites More sharing options...
shlomikalfa Posted May 21, 2008 Share Posted May 21, 2008 well... as far as i can tell.... it seems like your host is using a shared directory for all session files.... i had the same issue... what i did was: 1. open a new file which i "include" into all other files of the site. 2. placed the following line in it: session_save_path(getcwd()."/Saved_Sessions") this will make the sessions to be placed under the same dir "Saved_Sessions" inside your site P.S -> you have to create that DIR. [you can use any dir you wish.] Link to comment https://forums.phpfreaks.com/topic/106663-access-session-variables-from-a-different-directory/#findComment-546734 Share on other sites More sharing options...
revraz Posted May 21, 2008 Share Posted May 21, 2008 You want to change that session save path in your .ini to something that you can actually see in your webroot. Link to comment https://forums.phpfreaks.com/topic/106663-access-session-variables-from-a-different-directory/#findComment-546738 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2008 Share Posted May 21, 2008 Check your actual settings using a phpinfo(); statement. It's possible that the php.ini that you are looking at is not the one that php is using. session.cookie_path = / is correct to allow the session cookie to match any path, assuming that the settings in your php.ini are actually being used. The session cookie path and session cookie domain operate the same as a regular cookie. See the setcookie() page in the php manual for a description of what those two settings mean. Link to comment https://forums.phpfreaks.com/topic/106663-access-session-variables-from-a-different-directory/#findComment-546740 Share on other sites More sharing options...
webfeet Posted May 21, 2008 Author Share Posted May 21, 2008 I checked phpinfo() and discovered that it is indeed using the php.ini file I see. I changed session.save_path to /, then /www. Neither works. It appears that if session.save_path is anything but /tmp, the session variables do not get saved at all, even in the same directory. I am still unable to set a session variable in one folder, and access it from another. Any other ideas? Shall I just give up and use a cookie? That, of course, means that if the user has disabled cookies, my code will not work. Link to comment https://forums.phpfreaks.com/topic/106663-access-session-variables-from-a-different-directory/#findComment-546911 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2008 Share Posted May 21, 2008 The posts concerning session save path were off base and have nothing to do with the directory in the url that sessions work under. There are literally 100's of thousands, if not millions of web sites using sessions that work when changing paths in the url. Something specific is occurring on your server/site/code that is preventing them from working. Do sessions work when going between pages in the same path? Add the following two lines to both the starting page and the page you are going to - ini_set ("display_errors", "1"); error_reporting(E_ALL); Show the two url's you are trying (xxxxx out your domain if you don't want to post it.) How are you navigating between the two url's? A link on a page? A redirect? The session cookie is just a regular cookie that holds the session id. Are you using the session.use_trans_sid to propagate the session id? Finally, post your code for both pages so that someone could see if it is doing something or so that they could attempt to duplicate the problem. Link to comment https://forums.phpfreaks.com/topic/106663-access-session-variables-from-a-different-directory/#findComment-546946 Share on other sites More sharing options...
revraz Posted May 22, 2008 Share Posted May 22, 2008 No they weren't, chances are sessions were not working at all. You're right, sessions could care less about what folder the code is in, but they have to work first before you can use them. The posts concerning session save path were off base and have nothing to do with the directory in the url that sessions work under. Link to comment https://forums.phpfreaks.com/topic/106663-access-session-variables-from-a-different-directory/#findComment-546991 Share on other sites More sharing options...
PFMaBiSmAd Posted May 22, 2008 Share Posted May 22, 2008 Probably reading what the OP posted would help - I changed session.save_path to /, then /www. Neither works. It appears that if session.save_path is anything but /tmp, the session variables do not get saved at all, even in the same directory. Link to comment https://forums.phpfreaks.com/topic/106663-access-session-variables-from-a-different-directory/#findComment-547034 Share on other sites More sharing options...
revraz Posted May 22, 2008 Share Posted May 22, 2008 Probably because he doesn't know how to properly set the session save path. He is probably trying to use a path like /folder instead of the entire webroot path which is required. Link to comment https://forums.phpfreaks.com/topic/106663-access-session-variables-from-a-different-directory/#findComment-547280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.