Re: session management
| From: | Mark Faine | Date: | Tue, 08 Aug 2000 13:55:03 +0000 |
| Subject: | Re: session management | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10659@lists.php.net to get a copy of this message | ||
if(!isset($SESSION)){
session_register("SESSION");
}
$SESSION is an array, and is now registered, anything you assign to $SESSION
like this
$SESSION["username"]="foo";
will now be available as a session variable that you can echo back out like
this:
echo $SESSION["username"];
You should read the documentation on sessions, also phpbuilder has a lot of
good articles, and web monkey as well.
Hope that helps
-Mark
"Richard Jones" <rikki@ultramail.co.uk> wrote in message
news:00080813240602.10895@arthur...
> 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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>