RE: [PHP-DB] losing my session variables
| From: | Ford, Mike [LSS] | Date: | Wed, 30 Oct 2002 11:34:16 +0000 |
| Subject: | RE: [PHP-DB] losing my session variables | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-22818@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Peter Beckman [mailto:beckman@purplecow.com]
> Sent: 30 October 2002 04:09
> To: Seabird
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] losing my session variables
>
>
> Put "session_start()" somewhere in your code.
.. but make sure that "somewhere" is before you do any real output to your page!
> $_SESSION isn't set until you "start" your session.
>
> And don't set session variables by $_SESSION[foo] = bar;
>
> DO this:
>
> $foo = bar;
> session_register("foo");
>
> Much better.
No -- this is fraught with problems in current releases of PHP (most, if not all, of which will be
fixed in 4.3). Most particularly, the following caution appears at http://www.php.net/manual/en/ref.session.php:
"If you are using $_SESSION and disable register_globals, do not use session_register(),
session_is_registered() and session_unregister(), if your scripts shall work in PHP 4.2 and
earlier."
Since the default for 4.2.x is register_globals=off, this is a very pertinent warning!
Even with register_globals=on, there are other problems which make it best to stick to manipulating
the values in $_SESSION directly, rather than using the "equivalent" global variables.
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