xProteuSx Posted April 21, 2015 Share Posted April 21, 2015 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? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted April 21, 2015 Share Posted April 21, 2015 Try and put @session_start(); at the top of every page, even the included ones. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 21, 2015 Share Posted April 21, 2015 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. Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted April 21, 2015 Solution Share Posted April 21, 2015 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. Quote Link to comment Share on other sites More sharing options...
xProteuSx Posted April 22, 2015 Author Share Posted April 22, 2015 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.