We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Saving data between page loads - best practice?

Development and Programming

Yuri's avatar
Yuri
315 posts
14 years ago
Yuri's avatar Yuri

Hi to the community,

I have a bunch of data created on page (not EE template page, but module’s action page - if that matters) that I need to pass to another page (again, of ACT=xx type). I obviously can pass the data as GET request, but don’t really want to expose some of the data in any way. Another option is setting the cookie for each variable, but it looks a bit awkward to me.

I would prefer saving data to session (whatever session type user has chosen). $this->EE->session->set_cache() unfotunately does not work between page loads. Trying to set directly $this->EE->session->my_variable does not work as well.

So, should I go with cookies or is there a better way? Any method that I’m not aware of?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

If you don’t want to use cookies on the client site you could use PHP’s native $_SESSION depending on the type of data you’re working with. You could also store temporary data in the DB, but I’d be sure to benchmark the options and be comfortable with the time required for those options.

       
Yuri's avatar
Yuri
315 posts
14 years ago
Yuri's avatar Yuri

Hi Erik, I remember running into some problems trying to use PHP’s native $_SESSION in EE 1.x Don’t remember what kind of problems those were though 😊 But will probably try this way, as EE2 might behave differently - thanks for pointing to this option.

       
Yuri's avatar
Yuri
315 posts
14 years ago
Yuri's avatar Yuri

Just so you know - $_SESSION is not accessible in EE :( var_dump($_SESSION) returns NULL

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

I just created 2 templates with PHP enabled and successfully recalled $_SESSION data on each page which never linked to one another.

What was the code you tried?

       
Yuri's avatar
Yuri
315 posts
14 years ago
Yuri's avatar Yuri

I placed the code in the module, not in template

As simple as $_SESSION[‘provider’] = $provider; in one function and

var_dump($_SESSION); in another

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

Looks like you still need session_start().

       
Yuri's avatar
Yuri
315 posts
14 years ago
Yuri's avatar Yuri

yes, just discovered that too thanks, Erik!

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

You bet!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.