Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts

    4.3.2 and unsetting a session var?

    PHP Code:
    session_start();
    if(
    is_array($_SESSION) && count($_SESSION) > 0)
        {
        foreach(
    $_SESSION AS $var=>$val)
            {
            
    $_SESSION[$var] = '';
            unset(
    $_SESSION[$var]);
            
    $GLOBALS[$var] = '';
            unset(
    $GLOBALS[$var]);
            
    session_unregister($var);
            global $
    $var;
            $
    $var '';
            unset($
    $var);
            }
        }
    session_unset();
    setcookie (session_name(), '', (time () - 2592000), '/'''0);
    session_destroy(); 
    You might be able to guess from that, that I've been trying for a while to either set the value to '' or totally unset the particular session variable.
    I have used the above in an auto-redirecting (session-killer) page and in a main page that doesn't redirect.
    A page on the site with

    if(isset($_SESSION['varname']) && $_SESSION['varname'] != '')
    {
    // this gets executed after all the unsetting
    }

    has the session var miraculously reappear.

    The buglist has a few references, most of which are slammed down as 'bogus' without any of the php developers actually informing how to unset a session variable so that it isn't accessible on the next page.

    buglist search
    4.3.2 bug notice

    Any ideas?
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A fair few hours down the line (and a few less hairs on the ol' head) and I gave up with using sessions for that bit and moved to using $_GET.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Normally you just delete a variable from a $_SESSION array like this:

    unset($_SESSION['varname']);

    I'm still dicyphering your code though - not that easy at all. A few general hints that might point at the source of the confusion:

    1. Don't use session_register, session_unregister if you use $_SESSION. There are strange cases where they cause trouble if used in the same script, yours might be one of them.

    2. foreach() operates on a copy of the original array.
    De gustibus non est disputandum.


  •  

    Posting Permissions

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