PHPackages                             phossa2/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. [Framework](/categories/framework)
4. /
5. phossa2/session

ActiveLibrary[Framework](/categories/framework)

phossa2/session
===============

A session library for PHP.

2.0.0(9y ago)177MITPHPPHP &gt;=5.4.0

Since Oct 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/phossa2/session)[ Packagist](https://packagist.org/packages/phossa2/session)[ Docs](https://github.com/phossa2/session)[ RSS](/packages/phossa2-session/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

phossa2/session
===============

[](#phossa2session)

[![Build Status](https://camo.githubusercontent.com/443bda21542dd8aa56af6527dfd03f5e33e0da5e186c1d341ab7577c4c9e08c4/68747470733a2f2f7472617669732d63692e6f72672f70686f737361322f73657373696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phossa2/session)[![Code Quality](https://camo.githubusercontent.com/cb2288ae2a65e90196774aad9fdac85f8668858284c311ef40e2928b6a02471e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70686f737361322f73657373696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phossa2/session/)[![Code Climate](https://camo.githubusercontent.com/1b753963e129ea44e45c93ba72dd920b8b6b40c7ff09b3227540efce8a5d4461/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70686f737361322f73657373696f6e2f6261646765732f6770612e737667)](https://codeclimate.com/github/phossa2/session)[![PHP 7 ready](https://camo.githubusercontent.com/528bf96fd7882dbfddc93bf584b82e1d65977198f45e682e1ce7fc5d2a02b231/687474703a2f2f7068703772656164792e74696d6573706c696e7465722e63682f70686f737361322f73657373696f6e2f6d61737465722f62616467652e737667)](https://travis-ci.org/phossa2/session)[![HHVM](https://camo.githubusercontent.com/ce619433c5a5fe6fc1d02d2d0077b0272b6705c1bf841722c18589bd653d7e92/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f70686f737361322f73657373696f6e2e7376673f7374796c653d666c6174)](http://hhvm.h4cc.de/package/phossa2/session)[![Latest Stable Version](https://camo.githubusercontent.com/b6b9e89e52222489775b71230dd562a3a2e98f007262547e6e6d27f4d1f6a4d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f70686f737361322f73657373696f6e2e7376673f7374796c653d666c6174)](https://packagist.org/packages/phossa2/session)[![License](https://camo.githubusercontent.com/4fc6538ded72843e26a272d300ce4c95da083ce92576e10e4fdd505d579a8125/68747470733a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e737667)](http://mit-license.org/)

**phossa2/session** is a session library for PHP.

It requires PHP 5.4, supports PHP 7.0+ and HHVM. It is compliant with [PSR-1](http://www.php-fig.org/psr/psr-1/ "PSR-1: Basic Coding Standard"), [PSR-2](http://www.php-fig.org/psr/psr-2/ "PSR-2: Coding Style Guide"), [PSR-3](http://www.php-fig.org/psr/psr-3/ "PSR-3: Logger Interface"), [PSR-4](http://www.php-fig.org/psr/psr-4/ "PSR-4: Autoloader"), and the proposed [PSR-5](https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md "PSR-5: PHPDoc").

Highlights
----------

[](#highlights)

- Able to co-exists with other session libs or utilities including PHP session.
- Able to run [multiple sessions](#multiple) at the same time.
- Data seperation using [cartons](#carton).
- [Handler](#handler), [driver](#driver), [validator](#validator) support and dependency injection.
- [Middleware](#middleware) support.

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

[](#installation)

Install via the `composer` utility.

```
composer require "phossa2/session"
```

or add the following lines to your `composer.json`

```
{
    "require": {
       "phossa2/session": "2.*"
    }
}
```

Usage
-----

[](#usage)

Start the session, normally in your bootstrap file.

```
use Phossa2\Session\Session;
use Phossa2\Session\Carton;

// start a 'global' session
$sessGlobal = new Session('global');

// set 'global' session as the default
Carton::setDefaultSession($sessGlobal);

// start another 'private' session at the same time
$sessPrivate = new Session('private');
```

Then in your code using session data,

```
// a box using default session 'global'
$boxGlobal = new Carton();

// global counter
++$boxGlobal['counter'];

// another box named 'toy' using the private session
$boxPrivate = new Carton('toy', $sessPrivate);

// private counter
++$boxPrivate['counter'];
```

Features
--------

[](#features)

- **Multiple sessions supported**

    `Phossa2\Session\Session` uses its own infra-structure. It can co-exists with other session libs or PHP session. By default, it uses cookie as session id exchange protocol. Different session then use different cookies.

    ```
    // use a cookie named 'one'
    $sessOne = new Session('one');

    // use a cookie named 'two'
    $sessTwo = new Session('two');
    ```

    Close or destroy one session has no influence on other sessions.
- **Data seperation using `Carton`**

    In PHP session, session data is stored in the global variable `$_SESSION`. It provides storage only and there are no other utilities.

    `Phossa2\Session\Carton` is a sandbox for data. User may name a carton box instead of using the default name `'default'`. Or even attach to a different session instead of using the default session.

    ```
    // box 1
    $boxOne = new Carton('one', $sessPrivate);
    $boxOne['drone'] = 2;

    // box 2
    $boxTwo = new Carton('two', $sessPrivate);
    $boxTwo['drone'] = 1;
    ```

    If either `$name` or `$session` is different, then the data is in different namespaces.

    By extending `Phossa2\Session\Carton`, user may even provide utilities, such as data locking, usage monitoring, access control etc.
- **Extending the library**

    **phossa2/session** refactors most of its dependents into seperate classes.

    - *Session saving handler*

        Handler is implementing the most widely adopted `\SessionHandlerInterface`shipped in PHP. If no handler injected into session, it will utilize the `Phossa2\Session\Handler\FileHandler` by default.

        ```
        use Phossa2\Session\Handler\StorageHandler;

        // inject a phossa2/storage handler
        $session->setHandler(new StorageHandler($storage, '/tmp/session'));
        ```
    - *Session id exchange protocol*

        Driver is implementing `Phossa2\Session\Interfaces\DriverInterface`. By default, the `Phossa2\Session\Driver\CookieDriver` is used to `set/get/del`session id on the client side by using cookies.

        Users may write their own drivers to communicate with the client.

        ```
        use My\Own\HeaderDriver;

        // stores session id in `X-My-Own-Session` header
        $session->setDriver(new HeaderDriver());
        ```
    - *Session validation*

        Multiple validators may be injected into session to do validation.

        ```
        use Phossa2\Session\Validator\RemoteIp;

        $session->addValidator(new RemoteIp());
        ```
    - *Session id generator*

        By default, session id is generated by a built-in routine. User may use his own generator such as using `phossa2/uuid`.

        ```
        use Phossa2\Session\Generator\UuidGenerator;

        $session->setGenerator(new UuidGenerator());
        ```
    - *Middleware support*

        Middleware of this lib can be found in [phossa2/middleware](https://github.com/phossa2/middleware)

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) from more information.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTE](CONTRIBUTE.md) for more information.

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.4.0
- phossa2/shared &gt;= 2.0.21

License
-------

[](#license)

[MIT License](http://mit-license.org/)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

3503d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e0ecf2ab11402101d86a36b457973b81149757a53a67dd048bbfb9025890abf?d=identicon)[phossa2](/maintainers/phossa2)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (10 commits)")[![phossa2](https://avatars.githubusercontent.com/u/19922046?v=4)](https://github.com/phossa2 "phossa2 (1 commits)")

---

Tags

frameworksessionphossaphossa2

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[cse/helpers-session

The helpers allows you to easily manage session data. START, SET, GET DELETE, HAS method session - all this is available in this library.

102.6k3](/packages/cse-helpers-session)

PHPackages © 2026

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