PHPackages                             anders/slim-session - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. anders/slim-session

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

anders/slim-session
===================

Session middleware and helper for Slim framework 3.

3.3.0(8y ago)022MITPHPPHP &gt;=5.5

Since Jun 26Pushed 8y agoCompare

[ Source](https://github.com/oskonnikov/slim-session)[ Packagist](https://packagist.org/packages/anders/slim-session)[ Docs](https://github.com/bryanjhv/slim-session)[ RSS](/packages/anders-slim-session/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (16)Used By (0)

slim-session
============

[](#slim-session)

Simple middleware for [Slim Framework 3](https://www.slimframework.com), that allows managing PHP built-in sessions and includes a `Helper` class to help you with the `$_SESSION`superglobal.

**For the middleware version for Slim Framework 2, please check out the `slim-2`branch in this repository.**

Installation
------------

[](#installation)

Add this line to `require` block in your `composer.json`:

```
"bryanjhv/slim-session": "~3.0"

```

Or, run in a shell instead:

```
composer require bryanjhv/slim-session:~3.0
```

Usage
-----

[](#usage)

```
$app = new \Slim\App;
$app->add(new \Slim\Middleware\Session([
  'name' => 'dummy_session',
  'autorefresh' => true,
  'lifetime' => '1 hour'
]));
```

### Supported options

[](#supported-options)

- `lifetime`: How much should the session last? Default `20 minutes`. Any argument that `strtotime` can parse is valid.
- `path`, `domain`, `secure`, `httponly`: Options for the session cookie.
- `name`: Name for the session cookie. Defaults to `slim_session` (instead of PHP's `PHPSESSID`).
- **`autorefresh`**: `true` if you want session to be refresh when user activity is made (interaction with server).

Session helper
--------------

[](#session-helper)

A `Helper` class is available, which you can register globally or instantiate:

```
$container = $app->getContainer();

// Register globally to app
$container['session'] = function ($c) {
  return new \SlimSession\Helper;
};
```

That will provide `$app->session`, so you can do:

```
$app->get('/', function ($req, $res) {
  // or $this->session if registered
  $session = new \SlimSession\Helper;

  // Check if variable exists
  $exists = $session->exists('my_key');
  $exists = isset($session->my_key);
  $exists = isset($session['my_key']);

  // Get variable value
  $my_value = $session->get('my_key', 'default');
  $my_value = $session->my_key;
  $my_value = $session['my_key'];

  // Set variable value
  $app->session->set('my_key', 'my_value');
  $session->my_key = 'my_value';
  $session['my_key'] = 'my_value';

  // Merge value recursively
  $app->session->merge('my_key', ['first' => 'value']);
  $session->merge('my_key', ['second' => ['a' => 'A']]);
  $letter_a = $session['my_key']['second']['a'];  // "A"

  // Delete variable
  $session->delete('my_key');
  unset($session->my_key);
  unset($session['my_key']);

  // Destroy session
  $session::destroy();

  // Get session id
  $id = $this->session::id();

  return $res;
});
```

Contributors
------------

[](#contributors)

[Here](https://github.com/bryanjhv/slim-session/graphs/contributors) are the big ones listed. 😄

TODO
----

[](#todo)

- Complete `Helper` tests. (thanks @Zemistr)
- Slim-specific tests (integration with Slim App).

License
-------

[](#license)

MIT

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 71% 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 ~54 days

Recently: every ~49 days

Total

14

Last Release

3266d ago

Major Versions

1.0.1 → 3.0.02016-05-13

2.1.0 → 3.0.12016-06-01

2.1.2 → 3.0.22016-06-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/ac71c65d6b053239764bc36a5578232e89e3106f49435628cef5114ad29521a7?d=identicon)[anders2014](/maintainers/anders2014)

---

Top Contributors

[![bryanjhv](https://avatars.githubusercontent.com/u/2767941?v=4)](https://github.com/bryanjhv "bryanjhv (22 commits)")[![mohammad-erdin](https://avatars.githubusercontent.com/u/656852?v=4)](https://github.com/mohammad-erdin "mohammad-erdin (3 commits)")[![Zemistr](https://avatars.githubusercontent.com/u/2613208?v=4)](https://github.com/Zemistr "Zemistr (3 commits)")[![asheliahut](https://avatars.githubusercontent.com/u/945619?v=4)](https://github.com/asheliahut "asheliahut (1 commits)")[![Farkie](https://avatars.githubusercontent.com/u/294921?v=4)](https://github.com/Farkie "Farkie (1 commits)")[![LucasPadilha](https://avatars.githubusercontent.com/u/6677271?v=4)](https://github.com/LucasPadilha "LucasPadilha (1 commits)")

---

Tags

middlewarehelperslimsession

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/anders-slim-session/health.svg)

```
[![Health](https://phpackages.com/badges/anders-slim-session/health.svg)](https://phpackages.com/packages/anders-slim-session)
```

###  Alternatives

[bryanjhv/slim-session

Session middleware and helper for Slim framework 4.

233961.5k16](/packages/bryanjhv-slim-session)[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[league/uri-components

URI components manipulation library

31932.3M67](/packages/league-uri-components)[beste/json

A simple JSON helper to decode and encode JSON

4222.7M3](/packages/beste-json)[chillerlan/php-settings-container

A container class for immutable settings objects. Not a DI container.

3427.3M21](/packages/chillerlan-php-settings-container)[akrabat/rka-slim-session-middleware

Simple session middleware for Slim Framework

45261.6k3](/packages/akrabat-rka-slim-session-middleware)

PHPackages © 2026

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