SessionManager opens and saves sessions, RequestSession holds one request’s session data, and SessionOptions describes the cookie.
Logging in
Ask the manager for the session, store what you need, and save it before returning. Everything is ready to autowire — no setup code is needed:AuthController.php
commit() saves the data and puts the session id into a cookie on the response. Always call it before returning — anything you set() without commit() is thrown away when the request ends.
Reading the session on the next request
Open the session the same way. If the browser sent back a valid session cookie, you get the stored data; otherwise you get a fresh, empty session:Logging out
Cookie settings
SessionOptions is a plain object — you create one per login flow with new, right where you use it. Different flows need different cookies: an admin login might last 15 minutes on HTTPS only, while a regular user login lasts all day. Give each flow its own cookie name and they stay independent, even in the same browser:
open() and commit(). Both flows can share the same store — the cookie name keeps their sessions apart. If you only ever need one kind of login, one SessionOptions is enough.
Knowing who is logged in
Two fields travel with every session:username and session type. Set them at login:
1 for admins) — 0 simply means “no type set”.
Where sessions are kept
Out of the box, sessions are stored in files on the server — fine for getting started or a single server. For several servers, or sessions that must survive a restart, use a database or Redis instead by declaring one store bean (it must return\SessionHandlerInterface):
Database sessions
Create the table once:SessionConfig.php
created_at records when the session was first saved; updated_at refreshes on every save. Old, expired sessions can be cleaned up automatically.
Redis sessions
Thewinter-data-redis module offers dev\winterframework\data\redis\session\RedisSessionStore, which keeps each session as a hash under keyPrefix + sessionId and lets Redis expire old sessions by itself. Like the database store, it persists username and session type with the same write-once rule:
SessionConfig.php