session management
| From: | Richard Jones | Date: | Tue, 08 Aug 2000 12:24:06 +0000 |
| Subject: | session management | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-10646@lists.php.net to get a copy of this message | ||
Hello all,
I've just joined the mailing list, and am already wondering if someone can
help me. I am attempting to use an array as a session variable. About an
hour ago, it was working OK. It had some bugs, but in general it was doing
what I wanted. Feeling satisfied with my progress I take a break for a
cigarette, during which time the code decides that actually, it's not going
to work after all!!
I'm sure that I didn't touch anything between when it worked and didn't work
- my only guess is that maybe something was being cached somewhere, to hide
the fact that I'd broken it, but that it's quite unlikely.
I wrote:
//session management gumpf
session_start();
session_register($ARRAY);
/* check that the array has been set. If not, set it */
if(!isset($ARRAY) || !is_array($ARRAY)) {
$ARRAY = array();
echo "reset"; // just so I can see when it's doing this
}
include("products.php"); // other functions are contained in here
/* check that $pta (a number) is set. If it is, and $amount (another
number) is not set, then set $amount to 1, and then build the array */
if(isset($pta)) {
if (!isset($amount)) {
$amount = 1;
}
$ARRAY = build_cart_array($CART, $pta, $amount); // this works, and
$ARRAY is returned as a successfully built array.
}
// end of session management gumpf
The problem seems to be that further down the page that this is at the top
of, I call other functions which use $ARRAY. They all also manipulate the
array correctly, but some of them require that the page on which the above
code is stored be reloaded. Now, that /was/ OK until after my cigarette, and
everything behaved nicely, but suddenly the array checking code that prints
"reset" every time it runs is running every time that I reload the page, and
resets the array to being empty, which is not what I want.
My suspicions concern the session_register() function. I've read that it is
buggy (I don't know how true this is), and that it overwrites all session
variables when it runs. If this is the case, does anyone know how to get
round it, and any ideas why it wasn't causing problems before? Any help
would be thoroughly appreciated, as I've been banging my head against it for
some time now, and my brain is hurting.
Cheers,
Richard
"I need my sleep. I need eight hours a day ... and about ten at night."
Bill Hicks