The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

session variables + function ouput = PROBLEM (4 posts)

  1. volleyballmaniac
    Posted 8 years ago #

    I enabled sessions by adding a session start function to my wp-config file.

    Since then, I have happily been able to pass session variables between pages.

    Then came the day that I decided that I needed to store the output of functions into session variables. And that's where I hit a problem.


    I CAN assign session variables (like 1 or 'Hello World')using the following code:

    $_SESSION['JoeCatID'] = 1;

    I can then retrieve it on another page using this code:

    echo $_SESSION['JoeCatID'];


    but when I attempt to call a function and assign the function output into the session variable, like so:

    $_SESSION['JoeCatID'] = get_query_var('cat');

    I am no longer able to retrieve the session variable on another page (using the same retrieve code above).


    - I am able to assign and retrieve the function assigned session variable, if I assign & retrieve at the same time on one page load (place both functions on page).

    - but if I try to assign on one page, and then retrieve on another (with the session variable retrieve), the variable does not return properly.

    - If the function returns an INT (like get_query_var('cat')), on next page, it returns a "0".

    - If the function returns a string (like category_description()), on next page, it returns nothing (blank).

    - I even tested by assigning the function assigned session variable on Page 1, reloading Page 1 (to assign it); I then removed the assignment call, and replaced it with the retrieve call, and it fails.

    - so regardless of whether I call it on the Same Page, or a new page, the session is failing when I try to retrieve a function assigned session variable AFTER the Page Load.

    - however (as I said above) it works perfectly when I assign, and then try to retrieve a non-function variable (like 1 or 'Hello World').


    Those are all the details about the issue. I've been working for 2 days straight, but I can't seem to resolve it.

  2. volleyballmaniac
    Posted 8 years ago #

    I also tried calling the function first, and then assigning it to $_SESSION after, like so:

    $foo = get_query_var('cat');
    $_SESSION['JoeCatID'] = $foo;

    but that doesn't work either (same symptoms as noted in first posting).

  3. volleyballmaniac
    Posted 8 years ago #


    this is quite possibly the strangest error/bug I have ever dealt with, with WordPress (or perhaps its PHP).

    I had an animated Favicon Gif file in my header.php.
    <link rel="icon" href="animated_favicon1.gif" type="image/gif" >

    Once I removed that, my session problem was solved.

    I don't know how the heck that changed anything; quite honestly, I was just desperate so I just started removing things one by one to see if it fixed the problem.

  4. satranc
    Posted 7 years ago #


    You cant use Session variables at WordPress.

Topic Closed

This topic has been closed to new replies.

About this Topic