Download the PHP package tobento/service-session without Composer
On this page you can find all versions of the php package tobento/service-session. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tobento/service-session
More information about tobento/service-session
Files in tobento/service-session
Package service-session
Short Description Session support for PHP applications.
License MIT
Homepage https://www.tobento.ch
Informations about the package service-session
Session Service
Session support for any PHP applications.
Table of Contents
- Getting started
- Requirements
- Highlights
- Documentation
- Create Session
- Save Handlers
- PDO MySql Save Handler
- Null Save Handler
- Validation
- Remote Addr Validation
- Http User Agent Validation
- Stack Validation
- Custom Validation
- Start Session
- Interacting With Data
- Interacting With Flash Data
- Miscellaneous
- Save Session
- Session Middleware PSR-15
- Credits
Getting started
Add the latest version of the Session service project running this command.
Requirements
- PHP 8.0 or greater
Highlights
- Framework-agnostic, will work with any project
- Decoupled design
- Native Session or Using Save Handlers
- Flashing data
- Session PSR-15 Middleware
Documentation
Create Session
If the saveHandler parameter is null, it uses native session.
Session Factory
You might use the session factory to create the session.
Save Handlers
PDO MySql Save Handler
You might use the PDO mysql save handler to store session data in the database.
Database Table
Create Save Handler
Null Save Handler
You might use the Null save handler for testing purposes.
Validation
Remote Addr Validation
Http User Agent Validation
Stack Validation
You may use the Validations::class to procees multiple validations.
Custom Validation
You may write your own validation by implementing the ValidationInterface:
Start Session
Before storing or retrieving data from the session, you need to start the session. You might use the Session Middleware PSR-15 to do so.
Interacting With Data
set
Stores data in the session.
get
Get data from the session.
has
To determine if an item is present in the session returning a boolean.
delete
Delete data from the session.
deleteAll
Delete all data from the session.
all
Get all data from the session.
Interacting With Flash Data
Works only if the Save Session method is being called on every request end.
flash
Store data in the session for the current and next request.
now
Store data in the session for the current request.
once
Store data in the session. After first retrieving data, the flashed data will be deleted.
Miscellaneous
regenerateId
Regenerates new session id. Use it when changing important user states such as log in and logout.
destroy
Destroys the session altogether but does not regenerate its id.
name
Get the session name.
id
Get the session id.
Save Session
Saves and flashing the session data. You might use the Session Middleware PSR-15 to do so.
Session Middleware PSR-15
You may use the session middleware, which starts the session, adds the session as request attribute and finally calls the save method to save session data.\ Note that the session middleware handles only the SessionExpiredException.\ You may handle SessionStartException and SessionValidationException by your application error handling middleware or write your own session middleware fitting your application.
Credits
- Tobias Strub
- All Contributors