Originally posted by Arc
The session is originaly set when the user logs in. A name is retreived from the database and the session variable is set to that. For instance,
$_SESSION["SESSION_UNAME"];
[snip]
Why are you just implementing a session variable in such a way? You aren't really setting the variable, you're just referencing it. To set it you'd have to add this line below:
$Query = "SELECT UserID,BusinessName FROM tblUsers WHERE Username = '$txtUsername' AND Password = '$txtPassword' AND Active='TRUE'";
$Result = mysql_query($Query);
$ResultArray=mysql_fetch_array($Result);
$SESSION_UNAME = $ResultArray['BusinessName'];
// ADD THIS LINE
$_SESSION['SESSION_UNAME'] = $SESSION_UNAME;
Then at the top of my topnav.php page I have
session_start();
$_SESSION["SESSION_UNAME"];
I also don't understand this line either, it's very strange. What are you doing with the session variable here in topnav.php? If you wish to display you would do
echo $_SESSION['SESSION_UNAME'];
Then in my other pages I atempt to display this variable
<?php Print $SESSION_UNAME; ?>
That is not your session variable, that is a set variable that no longer exists upon going to other pages. You need to use $_SESSION['SESSION_UNAME'] instead within print_r, printf, sprintf or echo statements to view
Now, this works fine on the main page, but on any pages that were "included" the variable does not display. If I take one of the "included" pages and type it's URL manualy into the browser then the varaible displays as it should.
I am aware how "includes" work, but what other explination is there? The variables display fine on every page untill they are called with "include" then they no longer display the variable.
This could very well be something else, but I can't think of what it could be. I am doing everything right. [/B]
Not to sound like one of "those elitist programmers", but I'm going to in this case. I think you're not fully grasping the concept of session variables in PHP and I suggest you read up a bit more on it. Go to www.php.net and look up $_SESSION and study it thoroughly by example and see how they're utilizing it.
I just completed a section of my own app the other day using $_SESSION successfully. It sets and retrieves and I'm using multiple include and require_once, even retrieves within a class method inside an included file. Based on what you're telling me you're not doing much differently than me but your code looks disjointed and doesn't reflect that you know thoroughly how to use session variables just yet.
Phil