PHPackages                             stack/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. stack/session

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

stack/session
=============

Session stack middleware.

273.8k6[4 issues](https://github.com/stackphp/session/issues)2PHP

Since Jan 8Pushed 8y ago3 watchersCompare

[ Source](https://github.com/stackphp/session)[ Packagist](https://packagist.org/packages/stack/session)[ RSS](/packages/stack-session/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (2)

Stack/Session
=============

[](#stacksession)

Session stack middleware.

Enables the request session for subsequent middlewares.

Example
-------

[](#example)

Here's an example giving a silex app access to the session using stack/stack:

```
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;

$app = new Silex\Application();

$app->get('/login', function (Request $request) {
    $session = $request->getSession();

    $username = $request->server->get('PHP_AUTH_USER');
    $password = $request->server->get('PHP_AUTH_PW');

    if ('igor' === $username && 'password' === $password) {
        $session->set('user', array('username' => $username));
        return new RedirectResponse('/account');
    }

    return new Response('Please sign in.', 401, [
        'WWW-Authenticate' => sprintf('Basic realm="%s"', 'site_login'),
    ]);
});

$app->get('/account', function (Request $request) {
    $session = $request->getSession();

    if (null === $user = $session->get('user')) {
        return new RedirectResponse('/login');
    }

    return sprintf('Welcome %s!', $user['username']);
});

$stack = (new Stack\Builder())
    ->push('Stack\Session');

$app = $stack->resolve($app);
```

Options
-------

[](#options)

The following options can be used to configure stack/session:

- **session.storage.save\_path** (optional): The path for the NativeFileSessionHandler, defaults to the value of `sys_get_temp_dir()`.
- **session.storage.options** (optional): An array of options that is passed to the constructor of the session.storage service.

    In case of the default NativeSessionStorage, the possible options are listed on [the PHP manual's session configuration page](http://php.net/session.configuration).
- **session.default\_locale** (optional): The default locale, defaults to `en`.
- **session.cookie\_params** (optional): Override parameter values for the session cookie as listed on [the PHP manual's session\_get\_cookie\_params page](http://www.php.net/manual/en/function.session-get-cookie-params.php). (allowed keys: `lifetime`, `path`, `domain`, `secure`, and `httponly`)

Usage
-----

[](#usage)

The session middleware enables the `Session` object on the request. You can access it through the `Request` object:

```
$session = $request->getSession();

$session->start();
$foo = $session->get('foo');
$session->set('foo', 'bar');
```

Silex SessionServiceProvider
----------------------------

[](#silex-sessionserviceprovider)

Note that this middleware is a replacement for the silex SessionServiceProvider. If you want to use it with silex, you might want to define the `session` service as follows:

```
$app['session'] = $app->share(function ($app) {
    return $app['request']->getSession();
});
```

This is only needed if you have services that depend on the `session` service.

Inspiration
-----------

[](#inspiration)

This middleware is based on the silex SessionServiceProvider.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/88061?v=4)[Igor](/maintainers/igorw)[@igorw](https://github.com/igorw)

---

Top Contributors

[![simensen](https://avatars.githubusercontent.com/u/191200?v=4)](https://github.com/simensen "simensen (9 commits)")[![igorw](https://avatars.githubusercontent.com/u/88061?v=4)](https://github.com/igorw "igorw (7 commits)")[![cordoval](https://avatars.githubusercontent.com/u/328359?v=4)](https://github.com/cordoval "cordoval (1 commits)")[![mbessolov](https://avatars.githubusercontent.com/u/2725121?v=4)](https://github.com/mbessolov "mbessolov (1 commits)")

### Embed Badge

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

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

###  Alternatives

[webflo/drupal-finder

Helper class to locate a Drupal installation.

12655.9M240](/packages/webflo-drupal-finder)[laravel-zero/phar-updater

A thing to make PHAR self-updating easy and secure.

162.5M118](/packages/laravel-zero-phar-updater)[sheadawson/quickaddnew

A decorator for form fields that manage object relationships, to allow adding a new object on the fly through a dialog window. It can handle has\_one, has\_many or many\_many relationships. At the moment it has been tested / works on DropdownField and ListboxField. It works both in the CMS and in the frontend.

4234.6k7](/packages/sheadawson-quickaddnew)

PHPackages © 2026

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