RE: [PHP] Using unset with $_SESSION
| From: | Ford, Mike [LSS] | Date: | Wed, 28 Jan 2004 10:25:58 +0000 |
| Subject: | RE: [PHP] Using unset with $_SESSION | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-176026@lists.php.net to get a copy of this message | ||
On 27 January 2004 16:20, trlists@clayst.com wrote:
> On 27 Jan 2004 Stuart wrote:
>
> > In that case, try this...
> >
> > foreach (array_keys($_SESSION) as $key)
> > unset($_SESSION[$key]);
>
> Yes, I had tried that but forgot to mention it. It does work.
>
> However, I'm still mystified as to why unset($_SESSION) not only
> doesn't remove old data from the sesison file when the script exits,
> but prevents the new variable I create after that from being saved.
>
> Perhaps $_SESSION as created by PHP is special and is tied to the
> session storage, whereas if it is destroyed with unset and then
> recreated that link is lost. That would explain the behavior.
Yes, that is exactly the case.
You might like to take a look at session_write_close()
(http://www.php.net/session-write-close) in addition to the other
recommendations.
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@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211