Peculiar Session Issue
Posted: Wed Sep 17, 2003 10:10 am
I'm a Java developer who has FINALLY made my way into the realm of PHP and I am having a seemingly strange issue regarding session variables. Basically, I have created a simple controller class that redirects a user without setting http params by outputting javascript to change the page location. The code goes something like this:
//------------------------------------------>
session_start();
if (!session_is_registered('user_id')) {
SessionController::Redirect('login.php'); // send to the login page
}
else {
$bar = 'bar';
session_register('foo');
$_SESSION['foo'] = $bar;
}
//------------------------------------------>
This seems simple enough to me, but it appears that the session variable (foo) is being created and set to $bar even if the user is redirected to the login page. I even put some output statements in the above "else" statement, and those DID NOT execute, but the "session_register()" call apparently did. Is this a bug in PHP or are all session variables registered on a page implicitly even if the code does not execute?
Much thanks in advance for any tips. I have been stumped on this one for longer than I'd like to admit.
//------------------------------------------>
session_start();
if (!session_is_registered('user_id')) {
SessionController::Redirect('login.php'); // send to the login page
}
else {
$bar = 'bar';
session_register('foo');
$_SESSION['foo'] = $bar;
}
//------------------------------------------>
This seems simple enough to me, but it appears that the session variable (foo) is being created and set to $bar even if the user is redirected to the login page. I even put some output statements in the above "else" statement, and those DID NOT execute, but the "session_register()" call apparently did. Is this a bug in PHP or are all session variables registered on a page implicitly even if the code does not execute?
Much thanks in advance for any tips. I have been stumped on this one for longer than I'd like to admit.