Jump to content

Session Variable Accessibility?


xProteuSx
Go to solution Solved by mac_gyver,

Recommended Posts

Here is the setup:

 

login.html with a simple login form (username, password) --> login.php (checks username, password) --> if login is good login.php sets a bunch of session variables based on some database info, sends user to members/members.html (different directory).

 

At the top of members/members.html I have some include statements (navigation.php, which uses some of the session variables to display different navigation options).

 

So, here's the problem:

 

If the login is successful, and the session variables are set the session variables are not accessible within the included navigation.php file, which is at the top of the members.html page, but the same session variables are accessible on the members.html page, but outside the included navigation.php file.

 

What is going on?  Does this have something to do with scope?

 

Here's what I know:

 

- session variables are being set properly in the login.php file

- session variables are accessible in on the members/members.html file

- session variables are not accessible in the included file navigation.php which is at the top of the members/members.html file

 

I have checked over all the code tons of times, and have checked session variable accessibility and values everywhere.  I cannot understand why the session variables cannot be accessed in the included file on this page, though they are accessible in other files where navigation.php is included.

 

The only thing that I can think of is that everything is happening in the root directory, and then the user is being sent to the /members/ directory.  Could this have something to do with it?  Not as far as I know, but what do I know?

 

Link to comment
Share on other sites

Session_start is most likely the culprit. I wouldn't go so far as to recommend it in every 'include' file, but it does have to go near the start of every script that you pass control to. If you are using a header() command to trigger your members script, then definitely you need a session_start at the top of that one.

 

It's simply a good habit to put it at the beginning of every independent script you write.

Link to comment
Share on other sites

  • Solution

You need to show us how you are including the files. I suspect you are using a URL ( http://your_domain.com/some_path/some_file ), rather than a file system path ( file_system_path/some_file ), and the included code is running in a completely separate instance of the web server, which not only takes several 100 times longer than than using the file system to include the file, but it doesn't have access to the $_SESSION variables that are present in the main file.

Link to comment
Share on other sites

Thank you for your help guys!  In the end, it proved to be mac-gyvers reply that helped, because he was right:  I was using urls instead of file system paths.  As soon as I changed the includes to file system paths everything started to work.

 

Cheers, and my thanks to you all!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.