Download the PHP package lithemod/session without Composer
On this page you can find all versions of the php package lithemod/session. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lithemod/session
More information about lithemod/session
Files in lithemod/session
Package session
Short Description Manages user sessions, allowing you to store and retrieve both persistent and temporary information between requests, such as login data, preferences, and short-term data.
License MIT
Informations about the package session
Session
The session middleware in Lithe is responsible for managing user sessions, allowing you to store and retrieve persistent information between requests, such as login data and preferences.
1. Installing the Session Middleware
To use the session middleware in Lithe, you need to install it via Composer. Composer is a dependency management tool for PHP.
Step by Step:
- Open the terminal (command line).
-
Navigate to your project directory. Use the
cd
command to change to the directory where your Lithe project is located. For example: - Run the installation command:
This command will download and install the session middleware and its dependencies.
2. Configuring the Session Middleware
After installing the middleware, you need to configure it in your Lithe application. This is done using the use()
method.
Example Configuration:
Configuration Parameters
You can configure the session middleware with some important parameters:
- lifetime: Sets the session duration in seconds. The default is 2592000 (30 days).
- domain: Sets the domain for which the session cookie is valid.
- secure: Indicates whether the session cookie should only be sent over secure connections (HTTPS).
- httponly: If it should only be accessible via HTTP requests.
- samesite: Defines the SameSite attribute of the session cookie. It can be
'Lax'
,'Strict'
, or'None'
. - path: Defines the path where the session files will be stored.
Example Configuration with Parameters:
3. Using Session Variables
After configuration, you can access and manipulate session variables through the Request
object. Let’s see how to do this through routes.
Route Examples
Here are some examples of how to use session variables in Lithe routes.
Setting a Session Variable
Retrieving a Session Variable
Removing a Session Variable
Destroying All Session Variables
Checking if the Session is Active
Regenerating the Session ID
Getting the Session ID
Setting a New Session ID
Getting All Session Variables
Checking if a Session Variable Exists
4. Magic Methods
The session object also provides some magic methods for convenience:
-
__get($key)
: Retrieves the value of a session variable. __set($key, $value)
: Sets the value of a session variable.
Final Considerations
- Creating the Session Directory: The middleware ensures that the directory for storing sessions exists. If it does not, it will be created automatically.
- Error Handling: If any errors occur during session configuration or initialization, the middleware will log them and continue execution normally.
All versions of session with dependencies
lithemod/flow Version ^1.0
lithemod/log Version ^1.0
lithemod/session-support Version ^1.0