WordPress.org

Ready to get started?Download WordPress

Forums

Custom Session Variables Unset immediately? (6 posts)

  1. cactusphone
    Member
    Posted 7 years ago #

    I'm trying to set a custom session variable and it seems to be unset the next time the page is generated. Is this normal in wordpress? Is there a function for creating a custom session variable?

  2. Antonie Potgieter
    Member
    Posted 7 years ago #

    I was wondering about the same thing

  3. Mads Phikamphon
    Member
    Posted 7 years ago #

    I have exactely the same problem :(

  4. lourencobasso
    Member
    Posted 7 years ago #

    Me too!!!
    The problem is in the function wp_unregister_GLOBALS(), located in wp-settings.php.
    This fuction unset all globals variables, including the sessions variables.
    Unfortunely the code don't explain why this kind of thing is done!!!
    I'll try to change it, avoiding to unset de $_SESSION...

  5. betatea
    Member
    Posted 7 years ago #

    lourencobasso
    Actually that function only clears the corresponding values in $GLOBALS hash and does not touch the actual value in $_SESSION hash.

    So for example you set $_SESSION['key1'] and that function unsets $GLOBALS['key1'] so that $key1 become unaccessible but this does not affect $_SESSION['key1'] and you can use it after you initialize the session with session_start() function.

  6. beetlefish
    Member
    Posted 6 years ago #

    I couldn't find session_start() in my installation of WordPress so I added it to the wp-config.php file at the top.

    session_start();

    This enabled sessions.

Topic Closed

This topic has been closed to new replies.

About this Topic