PHPackages                             lazarusphp/sessionmanager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lazarusphp/sessionmanager

ActiveLibrary

lazarusphp/sessionmanager
=========================

Session manager for lazarus Framework

v2.0.0(3w ago)058↓100%MITPHP

Since May 29Pushed todayCompare

[ Source](https://github.com/Lazarusphp/SessionManager)[ Packagist](https://packagist.org/packages/lazarusphp/sessionmanager)[ RSS](/packages/lazarusphp-sessionmanager/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (1)Versions (13)Used By (0)

Lazarusphp Session Manager
==========================

[](#lazarusphp-session-manager)

#### Index

[](#index)

- [Whats new](#whats-new)
- [What is the Session manager](#what-is-the-session-manager)
- [Installing the Session Manageer](#installing-sessions-manager)
- [The Basics](#the-basics)
- [Assigning Sessions Values](#assigning-sessions-values)
- [Retrieving Session Values](#retrieving-session-values)
- [Overriding Configuration Data](#overriding-configuration-data)
- [The Session Writer Class](#the-session-writer-class)
- [Extra Session Options](#extra-session-options)
- [Enabling Session Manager for Standalone Mode](#enabling-session-manager-for-standalone-mode)
- [Custom Writer Requirements](#custom-writer-requirements)
- [Final Recommendation](#final-recommendation)
- [Deleting Sessions](#deleting-sessions)
- [Garabage Collection](#garbage-collection)

Current Version
---------------

[](#current-version)

Version 2.0.

Whats new?
----------

[](#whats-new)

- New Code Restructure
- New Instantiation Method
- New implementation for standalone methods
- optional Replacable Config Options.

What is the session manager.
----------------------------

[](#what-is-the-session-manager)

The Session manager is a Database driven Session handler, storing all session data within a database allowing for more control.

Installing Sessions Manager
---------------------------

[](#installing-sessions-manager)

```
composer require lazarusphp/sessionmanager

```

The Basics
----------

[](#the-basics)

the Session manager can be called at anytime within a website, however a first time instantiation to connect to a database is required.

### Instantiation

[](#instantiation)

Session manager can now work in both an integrated mode or as a standalone script.

**Integrated Mode**

Integrated mode is designed to work with LazaruasPhp Database and QueryBuilder, Although this can be combined with a standalone script, this methid relies on other scripts designed by lazarusphp.

**Standalone Mode**

Standalone Mode gives you the ability to overide the SessionWriter class with your own custom file, this gives the ablity to pass custom database instructions. to the required methods.

```
use LazarusPhp\SessionsManager\Sessions;
Sessions::create()->save();
```

upon instantiation of the class a staic instance will be created this allows the session to run on a singleton

Assigning Sessions Values
-------------------------

[](#assigning-sessions-values)

```
$sessions = Session::create();
$session->username = "mike";
$session->id = 1;
```

Retrieveing Session Values.
---------------------------

[](#retrieveing-session-values)

```
$sessions = Sessions::create();
echo $sessions->username;

echo $sessions->id;
```

Overriding Configuration data
-----------------------------

[](#overriding-configuration-data)

As of Version Session Manager 2.0 it is now possible to override all Configuration Values.

by default these values are as follows.

```
    [
        "days" => 7, // Days of how long the session will last
        "path"=>"/", // Path of the Session.
        "table" => "sessions", //Name of the Sessions table in the database.
        "name" => "sessions", // Session name by default it is sessions.
        "domain" => isset($_SERVER['HTTP_HOST']) ? '.' . $_SERVER['HTTP_HOST'] : '' // which domain is allowed to access this by default is set to a wildcard of the called domain name,
        "secure" => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'), // define if the session is to only be used on https
        "httponly" => false, // define if the session can only be used on http;
        "samesite" => "lax", // can be set to strict or lax defaulted to lax
    ];
```

Overriding config files is done on instantiation of the session and is chained like so.

```
Sessions::create()->withConfig([
        "days" => 8,
        "path"=>"/",
        "table" => "sessions",
        "name" => "sessions",
])->save();
```

any values not edited in the withConfig method will revert to the default value.

**Note about Defaults**By default days and table are already applied and are defaulted adding these key pairs will overwrite default values.

### The Session Writer class.

[](#the-session-writer-class)

The Session Writer class is a custom class designed to hold Database query requests for the open, close, read, write, destroy and gc methods. these methods are a requirement as they implemenet the SessionHandlerInterface interface.

Extra Session Options
---------------------

[](#extra-session-options)

### Deleting Sessions

[](#deleting-sessions)

the Session manager has the ability to remove individual Sessions or can remove them all as a whole by using the deleteSessions() method;

```
use Lazarusphp\SessionsManager\Sessions;

$sessions = Sessions::create();
// Delete Specific Sessions
$session->deleteSessions("username","email","password");

// Delete All Sessions
$sessions->deleteSessions();
```

Be Aware that deleting all Sessions (Not Specifying Sessions) Will do a session\_destroy() call and will also delete the entire session from the database whereas choosing the sessions will only remove the specific values from the database, keeping the session intact. this will override anything currently set by the server.

### Garbage Collection

[](#garbage-collection)

Garbage collection is a built in function from php and is used to delete Generated Sessions which have expired, this can be done by using the session\_gc function

```
session_gc();
```

once called the script will go through all the sessions and will delete any stale records which hold an expiry set before the current timestamp. This can be triggered using the `session_gc()` function:

```
session_gc();
```

The function iterates through all sessions and removes expired records where the expiration timestamp is earlier than the current time.

Enabling Session Manager for standalone mode.
---------------------------------------------

[](#enabling-session-manager-for-standalone-mode)

Similar to overriding config files, you can override the SessionWriter class with a custom implementation. This allows you to connect to a dedicated database and use custom database queries for session management. Configure this at instantiation time like so:

```
use App/Writers/SessionWriters/CustomWriter;
Sessions::create()->withWriter(CustomWriter::class)->save();
```

Custom Writer Requirements
--------------------------

[](#custom-writer-requirements)

Using a custom writer must adhere to the rules imposed by `SessionHandlerInterface` and LazarusPhp `SessionInterface` files.

### SessionInterface Requirements and Recommendations

[](#sessioninterface-requirements-and-recommendations)

When implementing a custom writer, your class must implement the `SessionHandlerInterface` and follow the `SessionInterface` specifications. This ensures compatibility with the Session Manager.

Required methods:

- `open(string $path, string $name): bool`
- `close(): bool`
- `read(string $id): string|false`
- `write(string $id, string $data): bool`
- `destroy(string $id): bool`
- `gc(int $max_lifetime): int|false`

For more information, see [SessionHandlerInterface documentation](https://www.php.net/manual/en/class.sessionhandlerinterface.php).

**passConfig(array $config):voic**

```
public function passConfig(array $config):void
{
    $this->config = $config;
}
```

[click here](https://www.php.net/manual/en/class.sessionhandlerinterface.php) : for information on SessionsHandlerInteface

Final Recommendation
--------------------

[](#final-recommendation)

As part of the LazarusPhp framework, Session Manager implements a helper function called `session()`. This function provides convenient access to the Sessions class. You can use it for both initialization and accessing session data throughout your application.

```
function session():SessionManager
{
    return Sessions::create();
}
// Access can then be done like so.

session()->username = "test";

echo session()->username;
```

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance98

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~58 days

Recently: every ~97 days

Total

12

Last Release

22d ago

Major Versions

1.1.4 → v2.0.02026-02-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/42fe8da43e075694b07eeec0a2fb822ab60aa872bf765cb0434b919b43264479?d=identicon)[mbamber1986](/maintainers/mbamber1986)

---

Top Contributors

[![itzzpadre](https://avatars.githubusercontent.com/u/30671636?v=4)](https://github.com/itzzpadre "itzzpadre (116 commits)")

### Embed Badge

![Health badge](/badges/lazarusphp-sessionmanager/health.svg)

```
[![Health](https://phpackages.com/badges/lazarusphp-sessionmanager/health.svg)](https://phpackages.com/packages/lazarusphp-sessionmanager)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
