I have a problem with passing session variables between folders. I have a working login, and several session variables are created after a successful login. The session works fine until I try to use a script that is located in a different folder or directory. All of my scripts include a login process that is activated if the session id is not found. This is what happens as soon as a script in a different directory to that containing the original login is called. Obviously the session variables are not being passed to the new directory, even though they are clearly being created for the original session.
Can anyone explain this, and suggest a solution, as it is not acceptable to be asking the user to log in every time a script is called from a different directory.

Recommended Answers

All 5 Replies

Session , by a browser perspective , has a domain identifier. It doesn’t matter where your program is located (or in what directory) just where its domain points to. Remember that for browsers sub domains like www.sub.domain.com are different domains.

Well, I sort of understand, but not really. Can you explain further, or suggest a solution. I prefer to keep some related scripts in different folders to help with website organisation.

Well I will explain it shortly (meaning that there are more technical clarifications that I am not dealing with). Session is stored in your server as plain text (example /tmp/ sess_03eae2808a20f8aeb901aa86fb0fc2ad) there are all the data, even the objects unserialized.

Browser keeps the seesion id in the request header (If you set no other in the Cookie field … example install firebug and see in Net>Cookie> PHPSESSID=341e442d8087aafe4198ad450a359306; or something like that , that doesn’t mean that the cookie is stored in the clients cookie directory, it could be stored as well in the browser’s cookie – tokens memory).

If all the scripts – programmes that I am executing is under same domain (e.g. domain.com) and the client (browser) don’t restart then all of them should share the same session id. Of course I shouldn’t do anything with the session on my program and use in PHP just session_start(); . If one of my programs is in deferent domain url (e.g. ex1.domain.com ) then they don’t share the same session id in the browser.

Then it appears that there is little I can do about it apart from restructuring my web page to allow for the session activities to remain in the same folder. Thanks for the time you have given me.

My friend , before reconstructing maybe the problem is not the folder . 1) by folder do you mean anything.domain.com or 2) domain.com/anything . In the second case the problem could by anyplace else and be more precise maybe how your session starts,,,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.