$_SESSION - how to access session variables on other pages
Posted: Thu Jun 20, 2002 12:43 pm
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
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