Re: [PHP] Using unset with $_SESSION

2004-01-29 Thread Justin Patrin
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.
My guess is that what unset does in 'unlinks' the data from the 
variable, but it doesn't destroy it. The garbage collection routine in 
PHP destroys the values when it sees that they aren't connected to a 
variable. When you unset($_SESSION) you lose the name $_SESSION for that 
data (effectively killing youra bility to modify session vars), but the 
data is still kept tied to the session internally in PHP. When you do 
$_SESSION['newVar'] = 'newVal'; after that, you're creating an all-new 
variable called $_SESSION that has nothing to do with the actual session 
data.

--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Using unset with $_SESSION

2004-01-28 Thread Ford, Mike [LSS]
On 27 January 2004 15:52, [EMAIL PROTECTED] wrote:

 I am trying to find a reliable method to clean out all session
 variables and start clean. 
 
 Running PHP 4.3.1 on Win2K developing a web app to run on Linux.
 Session cookies are enabled, register globals is off.  I access all
 session variables with $_SESSION.
 
 What I have found is that if I use unset($_SESSION), set a single
 variable, and redirect, the OLD session data is passed to the
 new page.
 However if I use session_unset() or $_SESSION = array() and set my
 single variable, the data is passed properly.
 
 Shouldn't unset($_SESSION) work?

No.  The following Caution appears in the manual (at 
http://www.php.net/manual/en/ref.session.php#session.examples):

Caution 
Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the 
registering of session variables through the $_SESSION superglobal. 

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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Using unset with $_SESSION

2004-01-28 Thread Ford, Mike [LSS]
On 27 January 2004 16:20, [EMAIL PROTECTED] 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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Using unset with $_SESSION

2004-01-28 Thread trlists
  Shouldn't unset($_SESSION) work?
 
 No.  The following Caution appears in the manual (at
 http://www.php.net/manual/en/ref.session.php#session.examples): 
 
 Caution Do NOT unset the whole $_SESSION with unset($_SESSION) as
 this will disable the registering of session variables through the
 $_SESSION superglobal. 

Thanks -- I have to say I missed that one!

Thanks for noting session_write_close() as well.  I did try that, but 
it didn't seem to offer any advantages over letting the script write 
the data on exit.

 --
 Tom Rawson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Using unset with $_SESSION

2004-01-28 Thread Gryffyn, Trevor
Then there's session_destroy() too.

If I ever suggest something that seems correct on the surface, but
there's a good reason to use something else, even in particular cases,
feel free to let me know.  I think I know PHP fairly well, but it's so
flexible and there are usually a dozen ways to do things, I find a way
that work and use it.  I figure if you want to get rid of all your
session data, session_destroy() would do that.

Guess you'd have to do another session_start() after that though,
wouldn't you?  Hmm..See what happens when I use my brain?

-TG

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, January 28, 2004 8:33 AM
 To: [EMAIL PROTECTED]
 Cc: Ford, Mike [LSS]
 Subject: RE: [PHP] Using unset with $_SESSION
 
 
   Shouldn't unset($_SESSION) work?
  
  No.  The following Caution appears in the manual (at
  http://www.php.net/manual/en/ref.session.php#session.examples): 
  
  Caution Do NOT unset the whole $_SESSION with unset($_SESSION) as
  this will disable the registering of session variables through the
  $_SESSION superglobal. 
 
 Thanks -- I have to say I missed that one!
 
 Thanks for noting session_write_close() as well.  I did try that, but 
 it didn't seem to offer any advantages over letting the script write 
 the data on exit.
 
  --
  Tom Rawson
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Using unset with $_SESSION

2004-01-27 Thread Stuart
[EMAIL PROTECTED] wrote:
I am trying to find a reliable method to clean out all session 
variables and start clean.
http://php.net/session_destroy

--
Stuart
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Using unset with $_SESSION

2004-01-27 Thread trlists
On 27 Jan 2004 Stuart wrote:

  I am trying to find a reliable method to clean out all session 
  variables and start clean.
 
 http://php.net/session_destroy

That destroys the file but (at least the docs say) does not clean out 
the global variables, and does not seem to work in my example.

 --
 Tom Rawson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Using unset with $_SESSION

2004-01-27 Thread Stuart
[EMAIL PROTECTED] wrote:
On 27 Jan 2004 Stuart wrote:

I am trying to find a reliable method to clean out all session 
variables and start clean.
http://php.net/session_destroy
That destroys the file but (at least the docs say) does not clean out 
the global variables, and does not seem to work in my example.
In that case, try this...

foreach (array_keys($_SESSION) as $key)
unset($_SESSION[$key]);
Untested, but should work.

--
Stuart
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Using unset with $_SESSION

2004-01-27 Thread trlists
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.

 --
 Tom Rawson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php