Title: session variables    function ouput  =  PROBLEM
Last modified: August 19, 2016

---

# session variables function ouput = PROBLEM

 *  [volleyballmaniac](https://wordpress.org/support/users/volleyballmaniac/)
 * (@volleyballmaniac)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/session-variables-function-ouput-problem/)
 * 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:
 *     ```
       <?php
       $_SESSION['JoeCatID'] = 1;
       ?>
       ```
   
 * I can then **retrieve **it on another page using this code:
 *     ```
       <?php
       echo $_SESSION['JoeCatID'];
       ?>
       ```
   
 * ——————————-
    **PROBLEM**
 * but when I attempt to call a function and **assign **the function output into
   the session variable, like so:
 *     ```
       <?php
       $_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).
 * ————————————–
 * **WEIRD SYMPTOMS WHICH MIGHT HELP**
    – 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.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [volleyballmaniac](https://wordpress.org/support/users/volleyballmaniac/)
 * (@volleyballmaniac)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/session-variables-function-ouput-problem/#post-814560)
 * I also tried calling the function first, and then assigning it to $_SESSION after,
   like so:
 *     ```
       <?php
       $foo = get_query_var('cat');
       $_SESSION['JoeCatID'] = $foo;
       ?>
       ```
   
 * but that doesn’t work either (same symptoms as noted in first posting).
 *  Thread Starter [volleyballmaniac](https://wordpress.org/support/users/volleyballmaniac/)
 * (@volleyballmaniac)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/session-variables-function-ouput-problem/#post-814565)
 * SOLVED!
 * 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.
 *  [satranc](https://wordpress.org/support/users/satranc/)
 * (@satranc)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/session-variables-function-ouput-problem/#post-814920)
 * Hi,
 * You cant use Session variables at WordPress.
    [http://blog.ginchen.de/en/2008/08/15/session-variablen-in-wordpress/](http://blog.ginchen.de/en/2008/08/15/session-variablen-in-wordpress/)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘session variables function ouput = PROBLEM’ is closed to new replies.

## Tags

 * [assignment](https://wordpress.org/support/topic-tag/assignment/)
 * [session](https://wordpress.org/support/topic-tag/session/)
 * [session variables](https://wordpress.org/support/topic-tag/session-variables/)
 * [variables](https://wordpress.org/support/topic-tag/variables/)

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 3 replies
 * 2 participants
 * Last reply from: [satranc](https://wordpress.org/support/users/satranc/)
 * Last activity: [17 years, 4 months ago](https://wordpress.org/support/topic/session-variables-function-ouput-problem/#post-814920)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
