I am needing to set and and retrieve a variable within this addon. For example on one page my module connects to a remote server and gets an auth code. I would then use that auth code for all subsequent requests back to that remote server.

I assumed that like in codeigniter i could just store this in a session, most likely the EE session. But everything i have tried does not store for the period of the session, just the time it is set.

Am i being a numpty? Or do i need to roll my own session setup and storage?

Thanks, N


I think I would use the cache vs. the user data. The userdata is tied to the specific member that is logged in. The session cache is more appropriately used for add-ons (or developers) wanting to retrieve information in a subsequent method call.

$this->EE->session->set_cache('your_addon', 'your_cache_var', 'some value');

$cache = $this->EE->session->cache['your_addon']['your_cache_var']' // return 'some value'
  • Yes, Justin is correct. It would be better way. Apr 25 '13 at 16:22
  • 1
    $this->EE->session->set_cache('your_addon', 'your_cache_var', 'some value'); This works - but only for the current page request. It is not persistent data in the session, more like flash data in the session. So i think this leaves only native PHP Sessions. Thanks Apr 25 '13 at 16:36
  • If that is the case, I would use the system/expressionengine/cache directory. EE doesn't support PHP sessions natively, so I would avoid using them. Use the cache directory or set a cookie. Take a look at how CartThrob does it with their shopping cart. They use a combination of cookies and DB records. Apr 26 '13 at 17:29

With the EE session class you can set user data like:

$this->EE->session->set_userdata(array('session_name' => $value));

to get this user session data:

$session_name = $this->EE->session->userdata('session_name');

It would be better to use global session variable $_SESSION.


if (session_id() == "") 

  • Yes i am currently using the native PHP method, but ideally wanted to store it within the native EE session. I am guessing you are saying you cannot. Thanks, N Apr 25 '13 at 15:36
  • as I mentioned you can store user session data. Please see my updated answer. I hope, it would work for you. Apr 25 '13 at 15:45
  • Fatal error: Call to undefined method EE_Session::set_userdata() Apr 25 '13 at 16:35
  • FYI ExpressionEngine 2.0 removed the set_userdata() function. For a workaround, see here: ellislab.com/forums/viewthread/138599
    – nageeb
    Feb 25 '14 at 5:03

FYI ExpressionEngine 2.0 removed the set_userdata() function. For a workaround, see this thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.