After starting a session, I'm not able to access a session variable with $_SESSION['var_name']. I'm totally new to this so I'm probably doing something wrong. I am using PHP 4.2+ with register_globals off, meaning I don't have to use session_register.
Here is my session starting code:
code:--------------------------------------------------------------------------------
// attempt to authorize user with database
$userID = auth($name, $pass);
if ($userID != -1) {
session_start();
$_SESSION['username'] = $name;
if ($success) {
header('location:eq_authorized.php');
}
} else {
header('location:eq_login.php?message=Ooops! Wrong username and/or password!');
}
--------------------------------------------------------------------------------
Then in eq_authorized.php, I have this code:
code:--------------------------------------------------------------------------------
if (isset($_SESSION['username'])) {
echo("yey!");
} else {
echo("waah");
}
--------------------------------------------------------------------------------
And it's not recognized the 'username' variable. I get no error message, and I'm pretty sure the session is getting started okay because I saw a session file in my Windows\Temp folder. What am I doing wrong
$_SESSION - how to access session variables on other pages
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
To see if anything is being set in the $_SESSION array add:
to your code.
Also try putting session_start() at the top of the script outside of the if loop.
Mac
Code: Select all
echo '<pre>';
print_r($_SESSION);
echo '</pre>';Also try putting session_start() at the top of the script outside of the if loop.
Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK