i have a associative session array
$SESSION['common']['do']
$
SESSION['common']['id']
$_SESSION['common']['msg']

When i try to unset the whole $_SESSION['common'] var

session_unregister("common"); works
unset($_SESSION['common']); does not work

when i try to unset only one element $_SESSION['common']['do']

unset($SESSION['common']['do']) works
session_unregister($
SESSION['common']['do']) does not work

Can anyone explain.

    Hi,

    if register_globals is set to on then you might need to do something like

    unset($_SESSION['common']);
    unset($common);

    Thomas

      as tsinka suggests, unsetting an index from the $SESSION array does not unset any global variables the were extracted from that array (either manually or by the register_globals state). thus, when you say "unset($SESSION['common']) does not work" i am suspicious. it (probably) works exactly as designed but you still have a global varibale called $common.

        you guys are right, if i do unset 2ice it works.

        i.e
        unset($_SESSION['common']);
        unset($common);

        So using session_unregister() is better as it clears any global variables the were extracted from the session array.
        I read on php.net that if you are using $_SESSION to register session vars then use unset and not session_unregister().

          Originally posted by harman
          So using session_unregister() is better as it clears any global variables the were extracted from the session array.
          I read on php.net that if you are using $SESSION to register session vars then use unset and not session_unregister().


          use of session_register() and session_unregister() is now depreciated. simply add/unset elements from the $
          SESSION array.

            Write a Reply...