For a module I’m developing I need to track a user session for all visitors to certain templates, so rather than reinvent I’d like use EE sessions, but guests always have a $SESS->userdata[‘session_id’] of ‘0’ unless logged in. I’m wondering if there’s an easy way I’m missing to change this behavior, or if I’d need to create an extension to override the default session behavior globally?
Any pointers would be appreciated, as I feel like I’m perhaps just missing something obvious here.
Thanks!
Derek - it’s a super basic cart type of functionality that visitors won’t be logging in to use. I just want to track what items they’ve added over a couple different pages. So I thought if an EE session_id is available for non-logged guests, it would just save me creating my own session/cookies to track what they’ve added to their cart (and subsequently save the info the database upon final “checkout”/submittal).
I don’t want to mess with the session handling for logged in members at all.
I’m still in the planning stages so I don’t have any specifics yet to offer, it might well be that I should keep what I’m doing completely separate from EE if having guests with a session_id messes up membership checks or something.
(disclaimer to anyone reading: this is not any type of EE commerce mod here, just a one-off event signup for a client 😜 ).
With the amount of modification you’d have to do to ExpressionEngine sessions to make this work, I think you are going to be much better off and end up with an easier to maintain solution by using something external from the Session class. Even with logged in members, the Session class is not designed to carry persistent data across page loads.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.