Re: session - why does this not work?

From: Date: Thu, 06 Sep 2001 07:31:12 +0000
Subject: Re: session - why does this not work?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-66164@lists.php.net to get a copy of this message
<Original message> From: Christian Haines <cmh@cobweb.com.au> Date: Thu, Sep 06, 2001 at 03:15:05AM +1030 Message-ID: <B7BC9AB9.AF45%cmh@cobweb.com.au> Subject: [PHP] session - why does this not work? > hi all, > > any ideas why this does not work? its just a simple script to test > multi-dimensional arrays. the count value should increment...should it not? > > many thanks in advance! > > <? > session_start(); > session_register("count[0]"); > > $count[0]++; > echo $count[0]."<br>&nbsp;<br>"; > > reset ($HTTP_SESSION_VARS); > while (list($key, $value) = each ($HTTP_SESSION_VARS)) { > echo "Key: $key; Value: $value<br>\n"; > } > ?> > <html> > > <body> > > <form name=test method=post action=session_test.php> > <input name=submit type=submit> > </form> > > </body> > </html> </Original message> <Reply> Try this instead: session_start(); session_register("count"); $count = array(); $count[0]++; Btw. faik a variable you session_register() will not be available in the $HTTP_SESSION_VARS before you've left the page. But I'm not sure, so you should check that out. You should check $count for existence btw, before you register it as a session variable. Ca. it's already registered as a session variable. Then you don't want to register it again. And besides that, what would you think of initializing variables? I mean... you increase $count[0], but from which value? I'd say something like this: --- PHP code --- session_start(); if (!isset ($count)) { $count = array(); $count[0] = 0; if (!session_is_registered) { session_register ("count"); } } $count[0]++; --- End of PHP code --- </Reply> -- * R&zE: -- »»»»»»»»»»»»»»»»»»»»»»»» -- Renze Munnik -- DataLink BV -- -- E: renze@datalink.nl -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- ««««««««««««««««««««««««

« previous php.general (#66164) next »