Session Variables Plugin
This is an Expression Engine plugin that allows you to store variables in PHP's native session.
Support can be found in the comments and in this EE forum thread.
Current Version: 1.0 (released 7 April 2008)
* Works with ExpressionEngine 1.6 and higher.
Concept
Sometimes you may want to temporarily store a variable for a short amount of time without writing a value to the database. Expression Engine's sessions do not allow this, however PHP's native sessions do.
This plugin allows you to use PHP's native session variables.
Find out more about PHP Sessions.
How It Works
The session variables plugin works by using PHP's native session to store variables on the server. The variables can easily be set, retrieved and deleted.
Here are some examples of how to use it:
// setting the language variable to french
{exp:session_variables:set name="language" value="french"}
// setting the language variable to the second segment
{exp:session_variables:set name="language" value="{segment_2}"}
// setting the language variable to the posted variable
{exp:session_variables:set name="language" value="POSTED_VARIABLE"}
// getting the language variable
You are currently viewing this page in {exp:session_variables:get name="language"}
// deleting the language variable
{exp:session_variables:delete name="language"}
When using the set function, the name parameter and value parameter are required.
POSTED_VARIABLE is a constant that specifies the value of the posted variable with the specified name (in the example above it would refer to $_POST['language']).
When using the get function, only the name parameter is required.
When using the delete function, only the name parameter is required.
Note: The lifetime of the session is set in the php.ini file (session.gc_maxlifetime) and is 1440 seconds by default. It can be changed using the ini_set function, however it can be reset in unpredictable ways. This article explains how and why.
Installation
- Download and unzip session_variables.zip
- Upload pi.session_variables.php to the system/plugins folder.
Download
You can download and use the plugin for free here:
If this plugin has helped you and you are feeling generous then feel free to make a small donation, it is much appreciated:







Comments
Julien
23 April 2008
Hello,
I just want to say a big thank you as I have been stuck with sessions in EE for quite a time. Your plugin was very helpful to me, thank you !
However, I just noted a small addition you might consider for your plugin: it could be good to be able to parse in a loop all session variables that have been entered, like a foreach loop in php.
Other than that it's perfect !
Julien
23 April 2008
I found small "bugs" however:
- the help you give in the plugin panel of EE is misleading; it tells to use {exp:session:delete name="language"} but the real syntax would be the one you gave in this post, that is session_variables instead of session !
- your plugin starts a php session even if it is already started; I've searched the php doc, and it says that the test if (session_id() == "") is not good to know whether a session exists or not.
In fact I found no solution for this, so I removed the block of your plugin that tests the existence of the session and put at the very top of my EE header a simple (with php on of course).
This is perhaps not the cleanest solution but it always works.
Regards
Ben
23 April 2008
hi julien, i'm glad you are finding the plugin useful. thanks for the note on the syntax, i'll change in next release.
the plugin uses the session_id() function so that a php session is not started if one already exists. i too have looked for a better solution and found none. apparently none exists (http://bugs.php.net/bug.php?id=16349&edit=1).
Jim Pannell
31 July 2008
Hi Ben
Thanks for the plugin - it looks great and has got me pretty excited! I'm just wondering how I would use this if I wanted to allow a user to click a link to set a session variable. Is this possible?
Cheers
Jim
Michael
24 September 2008
Hey, cool plugin. I'm not using it at the moment, but I stumbled across it looking for a solution to another issue.
You can probably do this as a better session check:
if(isset($_SESSION))
{
}
Mark
18 November 2008
I keep getting:
Session Plugin: name and value parameters must be entered
Help. What am I doing wrong?
Ben
18 November 2008
hi mark, you need to enter the name and value parameters when setting a session variable, so for example:
{exp:session_variables:set name="language" value="english"}
Jeff
19 November 2008
I'm having a heck of a time setting a session variable from a posted variable. Why is it that the session variable is always POSTED_VALUE? Is that an example?
Leave A Comment