unset($_SESSION['var']) fails

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

    unset($_SESSION['var']) fails

    PHP:
    unset($_SESSION['mainDisplay']);



    In my original environment (PHP 4.3.2) this line will delete the
    session variable 'mainDisplay'. But in the testing environment (PHP
    4.3.6) the variable persists even after unset() is called.

    Is there some special setting in PHP that can allow a session to
    persist even if you attempt to delete it? I am only able to delete the
    session variable upon closing the browser and rebooting computer.

    Thanx
    Phil
  • Sebastian Lauwers

    #2
    Re: unset($_SESSION['var']) fails

    Phil Powell wrote:
    [color=blue]
    > PHP:
    > unset($_SESSION['mainDisplay']);[/color]

    <?php
    session_start() ;

    if (isset ($_SESSION['mainDisplay']) ) {

    $_SESSION['mainDisplay'] = array();

    }
    ?>

    HTH,
    Best regards,
    Sebastian


    --
    The most likely way for the world to be destroyed,
    most experts agree, is by accident.
    That's where we come in; we're computer professionals.
    We cause accidents.
    --Nathaniel Borenstein

    Comment

    • Herbie Cumberland

      #3
      Re: unset($_SESSION['var']) fails

      apologies for top-posting, i just need to get this rant out of the way
      first:

      sebastian - please make sure you quote the message to which you
      replying in such a way as to make any further comments
      understandable. .. for this reason i've inserted the original question
      below, indented with pipes (|)


      On Fri, 23 Jul 2004 19:50:34 +0200, Sebastian Lauwers
      <?dacrashanddie ?no?@?spam?9onl ine.fr?> wrote:


      |PHP:
      | unset($_SESSION['mainDisplay']);
      |
      |In my original environment (PHP 4.3.2) this line will delete the
      |session variable 'mainDisplay'. But in the testing environment (PHP
      |4.3.6) the variable persists even after unset() is called.
      |
      |Is there some special setting in PHP that can allow a session to
      |persist even if you attempt to delete it? I am only able to delete the
      |session variable upon closing the browser and rebooting computer.
      [color=blue]
      >
      ><?php
      >session_start( );
      >
      >if (isset ($_SESSION['mainDisplay']) ) {
      >
      > $_SESSION['mainDisplay'] = array();
      >
      >}
      >?>[/color]

      and how is this meant to help?

      the OP asked why his $_SESSION variable was not getting unset when he
      asked it to ... assigning an empty array to the variable in question
      is /not/ really a fix to the problem.

      OP: RTM (http://www.php.net/manual/en/function.unset.php)

      specifically the User Contributed Notes as follows:

      [quote php.net]

      andre at twg dot com dot au
      07-Mar-2004 02:16

      Only This works with register_global s being 'ON'.

      unset( $_SESSION['variable'] );

      The above will not work with register_global s turned on (will only
      work outside of a function).

      $variable = $_SESSION['variable'];
      unset( $_SESSION['variable'], $variable );

      The above will work with register_global s on & inside a function

      [/quote php.net]



      Comment

      • Phil Powell

        #4
        Re: unset($_SESSION['var']) fails

        Herbie Cumberland <spamtrap@skipr aider.com> wrote in message news:<sd04g0tom 5iorbemmb4td26e ahn7ikmsap@4ax. com>...

        The above will not work with register_global s turned on (will only
        work outside of a function).

        $variable = $_SESSION['variable'];
        unset( $_SESSION['variable'], $variable );

        ------------------------------------------------------------------------------

        The caveat being "Work outside of a function". Sorry, but this has to
        occur within a class method, therefore, it doesn't work.

        What I found that does work, however, has been denounced by the PHP
        community at large, but not a single person can explain WHY this works
        in spite of the fact that the Manual says you can't:

        [PHP]
        print_r(ini_get ('register_glob als'))); echo '<p>';
        if ((int)ini_get(' register_global s') === 1)
        ini_set('regist er_globals', false);
        session_cache_l imiter();
        session_start() ;
        print_r(ini_get ('register_glob als'))); echo '<p>';
        [/PHP]

        In PHP 4.3.6 with register_global s ON this happens:

        1
        It successfully turned off register_global s, and I was able to, within
        my class method, successfully delete the session variable:

        [PHP]
        unset($_SESSION['mainDisplay']);
        [/PHP]

        I even tested in the other server which is PHP 4.3.2 with
        register_global s OFF and it works; turned it ON, it still worked!

        Phil

        Comment

        Working...