Description
How Plone handles anonymous and logged in user sessions. How to store and retrieve session data variables programmatically.
Sessions are visitor sessions at the site.
Sessions have features life
In Plone, sessions are managed by Zope’s session_data_manager tool. The source code is in Products.Sessions.
Plone has a tool called session_data_manager.
Example:
sdm = self.context.session_data_manager
session = sdm.getSessionData(create=True)
session.set("my_option", any_python_object_supporting_pickling)
Plone has a convenience method to get the session of the current user:
session = sdm.getSessionData(create=True)
Each session has unique id associated with it, this concerns both anonymous and logged-in users.
Session is based on browser cookies, so it is browser specific. If the same user has multiple browsers open on your site, all browsers have their own session.
If you need to refer to the session id, you can query for it:
sdm = self.context.session_data_manager
session_id = sdm.getBrowserIdManager().getBrowserId(create=False)
# Session id will be None if the session has not been created yet