Bizarre session variable behavior
| From: | Dan Kalowsky | Date: | Wed, 06 Dec 2000 13:45:45 +0000 |
| Subject: | Bizarre session variable behavior | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-40216@lists.php.net to get a copy of this message | ||
Encountered a bizarre session variable behavior last night...wondering
if anyone out there can help to decypher why this is happening...
Behavior:
created a session variable "sUserStatus" and proceeded to populate it
with results from a postgres query. immediately after this i created a
second session variable "sLangArray" and populated it from the postges
query.
the result was the "sLangArray" contained over 1/2 of the information
from the "sUserStatus", and its own data. the "sUserStatus" variable
seemed to be completely intact though when altering any of the
information in the now corrupt "sUserStatus."
these results were confirmed with a foreach loop printing to the screen
and a trigger_error dump of the output.
Solution:
solution found was just to change the order of request... create the
two session variables first, then populate the "sLangArray" THEN
populate the "sUserStatus."
Sample Code:
<?
// this was the bad code behavior
if (!session_is_registered("sUserStatus"))
{
session_register("sUserStatus");
unset($sUserStatus); // this was also attempted with $sUserStatus = "";
}
if (!isset($sUserStatus)) // this was also attempted with $sUserStatus
== "";
{
if($user_db->get_user_status_types($rv))
{
$sUserStatus = $rv;
}
else
{
trigger_error("Unable to retrieve user status types", E_USER_ERROR);
}
}
if(!session_is_registered("sLangArray"))
{
session_register("sLangArray");
unset($sLangArray); // this was also attempted with $sLangArray = "";
}
if (!isset($sLangArray)) // this was also attempted with $sLangArray ==
"";
{
if($user_db->get_lang_array($rv))
{
$sLangArray = $rv;
}
else
{
trigger_error("Unable to retrieve the lang array", E_USER_ERROR);
}
}
// end bad behavior
?>
<?
// the good behavior version!
if (!session_is_registered("sUserStatus"))
{
session_register("sUserStatus");
unset($sUserStatus); // this was also attempted with $sUserStatus = "";
}
if(!session_is_registered("sLangArray"))
{
session_register("sLangArray");
unset($sLangArray); // this was also attempted with $sLangArray = "";
}
if (!isset($sLangArray)) // this was also attempted with $sLangArray ==
"";
{
if($user_db->get_lang_array($rv))
{
$sLangArray = $rv;
}
else
{
trigger_error("Unable to retrieve the lang array", E_USER_ERROR);
}
}
if (!isset($sUserStatus)) // this was also attempted with $sUserStatus
== "";
{
if($user_db->get_user_status_types($rv))
{
$sUserStatus = $rv;
}
else
{
trigger_error("Unable to retrieve user status types", E_USER_ERROR);
}
}
?>
Misc Details:
PHP 4.0.4RC3 (will try RC4 later)
OS: FreeBSD 4.1.1-STABLE
PostgreSQL: 7.0.2
--
Dan Kalowsky "Tonight I think I'll walk alone,
Worldgate Communications I'll find my soul as I go home."
Software Engineer - TICS Group - Temptation