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

Storing session variables with PHP's native sessions

Development and Programming

Ben @PutYourLightsOn's avatar
Ben @PutYourLightsOn
295 posts
17 years ago
Ben @PutYourLightsOn's avatar Ben @PutYourLightsOn

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.

http://www.putyourlightson.net/projects/session_variables

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hi Ben,

Can’t believe this one slipped me by! Looks really handy. Going to check it out now. Thanks for all the great items you make for ExpressionEngine, they are really great.

Just to echo the sentiments of Julien on your comments on your site it would be great if you could somehow loop over items to add and retrieve from the sessions. This could then possibly be the basis of a sort of shopping cart or something like that? At the moment you would have to name the variables with a counter or something and track the count I suppose?

Anyway thanks for this as I am going to try it out right away.

Best wishes,

Mark

       
Ben @PutYourLightsOn's avatar
Ben @PutYourLightsOn
295 posts
17 years ago
Ben @PutYourLightsOn's avatar Ben @PutYourLightsOn

cheers mark, i appreciate it!

i find this one really handy, though i think most people haven’t really considered the possible uses of it. only thing that bugs me sometimes is that the default lifetime of a php session is 24 minutes

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Yep 24 minutes does seem a little odd although luckily on the server I am on I have full control over that sort of thing so would probably set it a lot higher than that.

Any thoughts on doing something like a shopping cart with this. What I mean to say is how hard would it be to add items to say something like an array in a session so that you can then just pull them all back at the end to show them in the cart and then send them off to say PayPal with the correct information?

Best wishes,

Mark

       
Ben @PutYourLightsOn's avatar
Ben @PutYourLightsOn
295 posts
17 years ago
Ben @PutYourLightsOn's avatar Ben @PutYourLightsOn

no reason why that wouldn’t work. i reckon a cookie might be better though so that next time the visitor comes to the site their cart contents will still be there. plus the lifetime of a cookie can be set to anything, including never-ending

       
Big Skillet's avatar
Big Skillet
364 posts
16 years ago
Big Skillet's avatar Big Skillet

I’m getting an error:

Cannot send session cookie - headers already sent by (output started at /path.php:14) in pi.session_variables.php on line 48
       
2ways's avatar
2ways
16 posts
15 years ago
2ways's avatar 2ways

Hi there,

The plugin is not showing up in my plugin list. I’ve got plenty of other plugins installed correctly in EE2.0, but this one isn’t appearing.

Thanks.

       
2ways's avatar
2ways
16 posts
15 years ago
2ways's avatar 2ways

Sorry. Problem solved.

For some reason, permissions were not set correctly on that upload. All is well.

Thanks for the plugin!

       
Euan's avatar
Euan
214 posts
15 years ago
Euan's avatar Euan

I have a scenario where the front page will give the user two options.

If they choose option 1 I want them to have a blue logo whilst they surf the site.

If they choose option 2 I want them to have a silver logo whilst they surf the site.

Would this do the job?

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
15 years ago
Matt Weinberg's avatar Matt Weinberg

That sounds like the perfect use of a cookie, Euan.

       

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.