Bug #17122 Updated: Values set in _SESSION doesn't stick

From: Date: Wed, 15 May 2002 12:03:25 +0000
Subject: Bug #17122 Updated: Values set in _SESSION doesn't stick
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-7743@lists.php.net to get a copy of this message
ID: 17122 Updated by: Leblanc@somewhere.com Reported By: mats@cdmedia.nu Status: Open Bug Type: Session related Operating System: Linux RH 7.2 PHP Version: 4.2.0 New Comment: what if you try : <? session_start(); session_register("foo"); session_register(4); session_register("a"); session_register("counter"); print "<PRE>"; print "Current values:\n"; print '"foo"=' . $_SESSION["foo"] . "\n"; print '4=' . $_SESSION[4]."\n"; print '"a"=' . $_SESSION["a"]."\n"; $_SESSION["foo"] = "bar"; $_SESSION[4] = "four"; $_SESSION["a"] = "b"; if(!isset($_SESSION["counter"])) $_SESSION["counter"] = 1; else $_SESSION["counter"]++; print "Count = ".$_SESSION["counter"]."\n"; print "</PRE>"; ?> $_SESSION["foo"] and $_SESSION["counter"] should be working $_SESSION[4] doesn't (I guess its because of the numerical key) and $_SESSION["a"] neither (but works if "a" is changed to "ab"). /Leblanc Previous Comments: ------------------------------------------------------------------------ [2002-05-09 11:34:40] mats@cdmedia.nu I'm having problems using $_SESSION, it throws away some of my values between page loads. The following code triggers the problem. <? session_start(); print "<PRE>"; print "Current values:\n"; print '"foo"=' . $_SESSION["foo"] . "\n"; print '4=' . $_SESSION[4]."\n"; print '"a"=' . $_SESSION["a"]."\n"; $_SESSION["foo"] = "bar"; $_SESSION[4] = "four"; $_SESSION["a"] = "b"; if(!isset($_SESSION["counter"])) $_SESSION["counter"] = 1; else $_SESSION["counter"]++; print "Count = ".$_SESSION["counter"]."\n"; print "</PRE>"; ?> The first run, it prints this: Current values: "foo"= 4= "a"= Count = 1 Which is what is expected, since the values haven't been set yet, except for the counter. Now the second run, this is where the problem show up: Current values: "foo"=bar 4= "a"= Count = 1 This seems to be wrong! The first value has been set, but none of the others. The counter should have been incremented also. The expected result of the second run would be Current values: "foo"=bar 4=four "a"=b Count = 2 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17122&edit=1

« previous php.bugs (#7743) next »