Professional Web Applications Themes

destroying a session - PHP Development

I know from php.net that when register_globals 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 ...

  1. #1

    Default destroying a session

    I know from php.net that when register_globals 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

    Marcus Guest

  2. #2

    Default Re: destroying a session

    "Marcus" <JumpMan222aol.com> skrev i en meddelelse
    news:3F0B959D.1030507aol.com...
    > 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?
    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


    Martin C. Petersen Guest

  3. #3

    Default Re: destroying a session

    Martin C. Petersen wrote:
    > 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
    >
    >
    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


    Marcus Guest

  4. #4

    Default Re: destroying a session

    Marcus wrote:
    > 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?
    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

    Cl1mh4224rd Guest

Similar Threads

  1. Replies: 17
    Last Post: September 12th, 11:42 PM
  2. Preventing the client from destroying the beauty
    By Glen@DIRTT in forum Macromedia Contribute General Discussion
    Replies: 4
    Last Post: April 28th, 03:19 PM
  3. Destroying models...
    By nickthenut in forum Macromedia Director 3D
    Replies: 4
    Last Post: June 10th, 08:59 PM
  4. Replies: 0
    Last Post: July 14th, 06:05 AM
  5. #24641 [NEW]: Displaying Warnning While Destroying Registered Session.
    By ashish1_sharma at rediffmail dot com in forum PHP Development
    Replies: 0
    Last Post: July 14th, 05:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139