Fastpress\Session is a modern, secure, and easy-to-use session management library for PHP. Crafted with simplicity and efficiency in mind, it seamlessly integrates with the Fastpress framework, yet remains flexible enough to be used in any PHP project. Whether you're building a small website or a large-scale application, Fastpress\Session provides a robust solution for handling session data securely and effectively.
- Simple and intuitive API: Easy to use methods for session manipulation.
- Flash messages support: Conveniently handle one-time messages for user feedback.
- Secure session handling: Enhanced security features to prevent common vulnerabilities.
- Flexible configuration: Customize session behavior to fit your application's needs.
- PSR-4 autoloading: Fully compliant with modern PHP standards.
Use Composer to install Fastpress\Session into your project:
composer require fastpress/session
- PHP 7.4 or higher.
Starts the session.
Returns:
true
if the session was started successfully,false
otherwise.
Regenerates the session ID.
Parameters:
$deleteOldSession
: Whether to delete the old session data.
Returns:
true
on success, throwsRuntimeException
on failure.
Generates a CSRF token.
Returns:
- The generated CSRF token.
Validates a CSRF token.
Parameters:
$token
: The token to validate.
Returns:
true
if the token is valid,false
otherwise.
Sets a flash message.
Parameters:
$key
: The key for the flash message.$value
: The value of the flash message.$type
: The type of flash message (e.g., 'info', 'success', 'error').
Returns:
void
Gets a flash message.
Parameters:
$key
: The key for the flash message.$default
: The default value to return if the flash message does not exist.
Returns:
- The flash message value or the default value.
Closes the session for writing.
Returns:
true
on success,false
otherwise.
Performs garbage collection on the session.
Parameters:
$force
: Whether to force garbage collection.
Returns:
true
on success,false
otherwise.
Destroys the session.
Returns:
void
Sets a session variable.
Parameters:
$key
: The key for the session variable.$value
: The value of the session variable.
Returns:
void
Gets a session variable.
Parameters:
$key
: The key for the session variable.$default
: The default value to return if the session variable does not exist.
Returns:
- The session variable value or the default value.
Checks if a session variable exists.
Parameters:
$key
: The key for the session variable.
Returns:
true
if the session variable exists,false
otherwise.
Deletes a session variable.
Parameters:
$key
: The key for the session variable.
Returns:
void
Clears all session variables.
Returns:
void