Tutorials: Working with HTTP Sessions
Configuring Session Creation
Even though the whole process can work without any further intervention, framework allows you to fine tune session creation via <session> tag @ stdout.xml. Among its attributes most important for developers are:
- handler: user-defined session handler class name (including namespace or subfolder) implementing \SessionHandlerInterface.
- auto_start: signals session to be started automatically for every request.
If your project requires session and expects to be deployed in a distributed web server environment, setting handler attribute is required. Framework comes by default with NoSQLSessionHandler, able to persist session in a clustered key-value store database (eg: Redis Cluster).
If your project is not RESTful and it features authentication & authorization, setting auto_start attribute is required.
Reading and Writing to Session
Framework uses STDOUT MVC API to encapsulate all session operations via Lucinda\STDOUT\Sessions. Latter defines following methods relevant for developers:
- start(): starts session, based on <session> settings if present. Called automatically if auto_start is set!
- isStarted(): checks if session is started
- set(KEY, VALUE): sets session parameter by key and value
- get(KEY): gets value of session parameter by key
- contains(KEY): checks if parameter exists in session by key
- remove(KEY): removes session parameter by key
- destroy(): destroys session, clearing of all parameters.