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']; ?>
——————————-
PROBLEMbut 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.
- The topic ‘session variables function ouput = PROBLEM’ is closed to new replies.