$_SESSION variable madness [rev title]
Posted: Sat May 02, 2009 9:44 am
The session variable is created in a menu script, conditionally the first time that the menu is executed.
This being a menu, it calls a bunch of other scripts, many of which use the $_SESSION vars, and one of which may alter the display var.
All of the "Cyr" and subsequent vars exist long before the menu script can be executed.
If the user calls any other script first, then the alteration of $_SESSION['DispStat'] occurs perfectly. If, however, the user calls the script which alters that variable immediately upon landing on that menu, that is the same execution of the script which initially sets that variable, then the alteration does not occur. The menu script is correctly using the $_SESSION['ListFor'] in that initial execution, but the $_SESSION['DispStat'] is used only in scripts called by the menu script.
Yes, session_start() is called at the beginning of all scripts. I have run them with error reporting set at E_ALL and gotten no errors. The call of the script that alters the variable is after the code that sets it. I thought of flushing right after it and tried that but, as expected really, no joy because the rest of the script had to have flushed or the menu would not be on the user's screen.
So, when does a $_SESSION variable actually exist? And why does the display variable not get altered if called immediately upon the menu creation, but successfully get altered at any other time?
Code: Select all
if (isset($_GET['Owner'])) // coming from main menu
{ $_SESSION['ListFor'] = 0 + $_GET['Owner'];
$_SESSION['DispStat'] = 4;
}
All of the "Cyr" and subsequent vars exist long before the menu script can be executed.
Code: Select all
if (isset($_SESSION['DispStat']))
{ if ($_SESSION['Cyr'] < $_SESSION['Lyr'] || ($_SESSION['Cyr'] == $_SESSION['Lyr'] && $_SESSION['Cmth'] <= $_SESSION['Lmth']))
$_SESSION['DispStat'] = 4;
else $_SESSION['DispStat'] = 5; // the status to display ("if Stat > $_SESSION['DispStat']")
}
Yes, session_start() is called at the beginning of all scripts. I have run them with error reporting set at E_ALL and gotten no errors. The call of the script that alters the variable is after the code that sets it. I thought of flushing right after it and tried that but, as expected really, no joy because the rest of the script had to have flushed or the menu would not be on the user's screen.
So, when does a $_SESSION variable actually exist? And why does the display variable not get altered if called immediately upon the menu creation, but successfully get altered at any other time?