destroying a session

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcus

    destroying a session

    I know from php.net that when register_global s is turned on,

    session_start() ;
    session_unset() ;
    session_destroy ();

    will succeed in unsetting all session variables and then destroying the
    session. I also read on the site that when using $_SESSION, you
    shouldn't use session_unset, but instead should use unset() to
    accomplish the 2nd of the above tasks. This example is then given:

    session_start() ;
    $_SESSION = array();
    session_destroy ();

    I'm just confused because I don't see exactly where unset() is being
    used... does the $_SESSION = array(); line do the same thing as unset(),
    and if so, is this all that is needed to completely close a session?

    Thanks so much for everyone's help, and also for everyone's patience
    while answering questions.

    Marcus

  • Martin C. Petersen

    #2
    Re: destroying a session

    "Marcus" <JumpMan222@aol .com> skrev i en meddelelse
    news:3F0B959D.1 030507@aol.com. ..[color=blue]
    > session_start() ;
    > $_SESSION = array();
    > session_destroy ();
    >
    > I'm just confused because I don't see exactly where unset() is being
    > used... does the $_SESSION = array(); line do the same thing as unset(),
    > and if so, is this all that is needed to completely close a session?[/color]
    Yeah, array() is just an empty array, so $_SESSION will be an empty array,
    which is the same as unsetting all elements in it..


    Martin


    Comment

    • Marcus

      #3
      Re: destroying a session

      Martin C. Petersen wrote:
      [color=blue]
      > Yeah, array() is just an empty array, so $_SESSION will be an empty array,
      > which is the same as unsetting all elements in it..
      >
      >
      > Martin
      >
      >[/color]

      Am I missing something then, because I checked in my PHP folder's
      sessiondata folder, and when I "destroy" sessions with this method, the
      file still remains on disk. When I try it with the first way (with
      register globals on), it immediately removes the associated session
      file. Any ideas why?

      Marcus


      Comment

      • Cl1mh4224rd

        #4
        Re: destroying a session

        Marcus wrote:[color=blue]
        > This example is then given:
        >
        > session_start() ;
        > $_SESSION = array();
        > session_destroy ();
        >
        > I'm just confused because I don't see exactly where unset() is being
        > used... does the $_SESSION = array(); line do the same thing as unset(),
        > and if so, is this all that is needed to completely close a session?[/color]

        You use unset() only when you want to get rid of individual session
        variables. Example:

        unset($_SESSION['username']);

        The example they gave sets the $_SESSION array to an empty array,
        essentially unset()ing all of the session variables at once.

        ~ Ryan

        Comment

        Working...