Unofficial port of laravel's illuminate/session.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Laraport Session Build Status

This php library is an unofficial port of laravel (L4) sessions. See illuminate/session for more details. The reason for this port is to consume it outside of laravel in a standalone project or another framework, where you find it tediuos to import the whole laravel framework.

This port currently supports the following drivers:

Requires PHP 5.4 or greater.

I have tried my best to load the minimum required libraries and have avoided laravel's container to ensure maximum portability.

Table of contents


This package can be installed by requiring it via composer.

$ composer require laraport/session


If you have consumed sessions in laravel (which i am sure you have), its now a cinch to consume it in a standalone project as well.

Array driver

The laravel configuration is loaded by default which is set to use the array driver.


require_once __DIR__ . '/vendor/autoload.php';

$Session = new Laraport\Session();
// ...
$Session->put('laraport', 'session');
// ... You know the rest, right?

File driver

To consume the file session driver, you may override the necessary configuration.


require_once __DIR__ . '/vendor/autoload.php';

$Session = new Laraport\Session([
    'driver' => 'file',
    'files' => __DIR__ . '/path/to/session'
// ...

Database driver

For the database session driver, you will need to pass the database connection array and set the table.

Any connection that illuminate/database understands, is supported.

The table is set to sessions by default.


require_once __DIR__ . '/vendor/autoload.php';

$Session = new Laraport\Session([
    'driver' => 'database',
    'table' => 'sessions',
    'connection' => [
        'driver'   => 'sqlite',
        'database' => $database,
        'prefix'   => ''
// ...

Custom driver

A custom implementation of php's SessionHandlerInterface is also supported. Simply set the instance of the implementation as the driver .


require_once __DIR__ . '/vendor/autoload.php';

$Session = new Laraport\Session([
    'driver' => new MyCustomSessionHandler(/*...*/)
// ...


First make sure you are in the project source directory.

Do a composer install.

$ composer install

Run the tests.

$ vendor/bin/phpunit


$ composer test

Similar projects

The above packages were the source of inspiration for this port.


Released under the MIT License.