Jump to content

Access Session variables from a different directory


webfeet

Recommended Posts

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 =

 

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.]

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.

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.

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.

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.

 

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. >:(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.