Re: session data missing
| From: | ulf sundin | Date: | Sun, 13 Jul 2003 22:36:53 +0000 |
| Subject: | Re: session data missing | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155028@lists.php.net to get a copy of this message | ||
I'm not the admin on the server, so I'll have to manage with the software
provided. And that is php 4.0.6.
I've tried a number of ways to store variables in the session file. This
works:
session_start();
$foo = 'bar';
session_register('foo');
then after session_write_close(); or end of script:
echo $HTTP_SESSION_VARS['foo']; will output 'bar'.
just adding variables directly into the HTTP_SESSION_VARS array won't make
them stick in the session file. Use of session_register() seems to be
required.
Ulf
"Mike Ford" <M.Ford@lmu.ac.uk> skrev i meddelandet
news:841D90E489448A4F804E1D1B95768BF7D46145@lis-exchange3.lmu.ac.uk...
> > -----Original Message-----
> > From: Kevin Stone [mailto:kevin@helpelf.com]
> > Sent: 09 July 2003 20:30
> >
> > ----- Original Message -----
> > From: "ulf sundin" <majikthse@spray.se>
> > To: <php-general@lists.php.net>
> > Sent: Wednesday, July 09, 2003 1:00 PM
> > Subject: Re: [PHP] session data missing
> >
> >
> > > ok, so now the variable names are registred and stored in
> > the file. But
> > > without values.
> > > check this:
> > >
> > > --firstpage.php----
> > > session_start()
> > > session_register('foo');
> > > $HTTP_SESSION_VARS['foo'] = 'bar';
> > > echo $HTTP_SESSION_VARS['foo']; //outputs bar;
> > >
> > > transport by a href to:
> > > ----secondpage.php----
> > > session_start();
> > > echo $HTTP_SESSION_VARS['foo']; //outputs nothing
> > >
> > > ---
> > > checking the contents of the file called /tmp/sess_{session_id}:
> > > !foo|
> > (snip)
> >
> >
> > Make a choice here..
> >
> > => session_register('foo');
> > => $HTTP_SESSION_VARS['foo'] = 'bar';
> >
> > Use either the session_register() function or the session
> > global array. Not
> > both.
>
> Not true -- $HTTP_SESSION_VARS is *not* like $_SESSION, and its values are
*not* auto-registered. In fact, I still have my copy of the 4.0.6 manual
around, and it specifically gives this as an example:
>
> > Example 1. Registering a variable
> >
> > <?php
> > session_register("count");
> > $HTTP_SESSION_VARS["count"]++;
> > ?>
>
> However, it's a little unclear on whether this should still work
regardless of the register_globals setting, as it also gives this as an
example:
>
> > Example 2. Registering a variable with register_globals enabled
> >
> > <?php
> > session_register("count");
> > $count++;
> > ?>
>
> I guess I'd have to go away and try it to be sure of what behaviour occurs
for each setting of register_globals -- but there seems little point given
that using $_SESSION has been much the best option for several versions now!
>
> Cheers!
>
> Mike
>
> ---------------------------------------------------------------------
> Mike Ford, Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS, LS6 3QS, United Kingdom
> Email: m.ford@lmu.ac.uk
> Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211