Download the PHP package bayfrontmedia/session-manager without Composer
On this page you can find all versions of the php package bayfrontmedia/session-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bayfrontmedia/session-manager
More information about bayfrontmedia/session-manager
Files in bayfrontmedia/session-manager
Package session-manager
Short Description A framework-agnostic PHP library to manage sessions using multiple storage options.
License MIT
Homepage https://github.com/bayfrontmedia/session-manager
Informations about the package session-manager
Session Manager
A framework-agnostic PHP library to manage sessions using multiple storage options.
- License
- Author
- Requirements
- Installation
- Usage
License
This project is open source and available under the MIT License.
Author
Requirements
- PHP
^8.0
- PDO PHP extension
Installation
Usage
Session handler
A \SessionHandlerInterface
must be passed to the Bayfront\SessionManager\Session
constructor.
There are a variety of session handlers available, each with their own required configuration.
In addition, you may also create and use your own session handlers to be used with Session Manager.
LocalHandler
The LocalHandler
allows you to store sessions in the local filesystem using native PHP.
PdoHandler
The PdoHandler
allows you to use a PDO
instance for session storage in a database.
Before using the PdoHandler
, the required database table must be created with the up
method,
and may throw a Bayfront\SessionManager\HandlerException
exception:
Start using Session Manager
Once your handler has been created, it can be used with Session Manager. In addition, a configuration array should be passed to the constructor.
Unless otherwise specified, the default configuration will be used, as shown below:
The cookie_*
keys allow you to configure the session cookie parameters.
The sess_regenerate_duration
key is the number of seconds interval before a new session is automatically created (prevents session fixation).
Set to 0
to disable automatically regenerating sessions.
The sess_lifetime
key is the number of seconds the session will be valid. Set to 0
for the session to be valid only "until the browser is closed".
The sess_gc_*
keys define the probability and divisor for the garbage cleanup.
NOTE: Be sure to call start before using any other methods to ensure the session has begun.
Public methods
- start
- startNew
- regenerate
- destroy
- getId
- getLastActive
- getLastRegenerate
- get
- has
- set
- forget
- flash
- getFlash
- hasFlash
- keepFlash
- reflash
start
Description:
Start a new session.
Parameters:
- None
Returns:
- (self)
Example:
startNew
Description:
Destroy existing and start a new session.
Parameters:
- None
Returns:
- (self)
Example:
regenerate
Description:
Regenerate new session ID.
When $delete_old_session = TRUE
, the old session file will be deleted.
Parameters:
$delete_old_session = false
(bool)
Returns:
- (self)
Example:
destroy
Description:
Destroy the current session file and cookie.
Parameters:
- None
Returns:
- (self)
Example:
getId
Description:
Return current session ID
Parameters:
- None
Returns:
- (string)
Example:
getLastActive
Description:
Return the last active time of the session.
Parameters:
- None
Returns:
- (int)
Example:
getLastRegenerate
Description:
Return the last regenerated time of the session.
Parameters:
- None
Returns:
- (int)
Example:
get
Description:
Returns value of single $_SESSION
array key in dot notation, or entire array, with optional default value.
Parameters:
$key = NULL
(string): Returns the entire array whenNULL
$default = NULL
(mixed)
Returns:
- (mixed)
Example:
has
Description:
Checks if $_SESSION
array key exists in dot notation.
Parameters:
$key
(string)
Returns:
- (bool)
Example:
set
Description:
Sets a value for a $_SESSION
key in dot notation.
Parameters:
$key
(string)$value
(mixed)
Returns:
- (self)
Example:
forget
Description:
Remove a single key, or an array of keys from the $_SESSION
array using dot notation.
Parameters:
$keys
(string|array)
Returns:
- (self)
Example:
flash
Description:
Sets a value for flash data in dot notation.
Flash data is available immediately and during the subsequent request.
Parameters:
$key
(string)$value
(mixed)
Returns:
- (self)
Example:
getFlash
Description:
Returns value of single flash data key in dot notation, or entire array, with optional default value.
Parameters:
$key = NULL
(string): Returns the entire flash array whenNULL
$default = NULL
(mixed)
Returns:
- (self)
Example:
hasFlash
Description:
Checks if flash data key exists in dot notation.
Parameters:
$key
(string)
Returns:
- (bool)
Example:
keepFlash
Description:
Keeps specific flash data keys available for the subsequent request.
Parameters:
$keys
(array)
Returns:
- (self)
Example:
reflash
Description:
Keeps all flash data keys available for the subsequent request.
Parameters:
- None
Returns:
- (self)
Example:
All versions of session-manager with dependencies
bayfrontmedia/php-array-helpers Version ^2.0
bayfrontmedia/php-cookies Version ^2.0
ext-pdo Version *