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

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

gears/session
=============

Laravel Sessions Standalone

v0.8.0(11y ago)162.0k2[5 issues](https://github.com/phpgearbox/session/issues)MITPHP

Since Sep 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/phpgearbox/session)[ Packagist](https://packagist.org/packages/gears/session)[ Docs](https://github.com/phpgearbox/session)[ RSS](/packages/gears-session/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (6)Versions (10)Used By (0)

> Looking for maintainers, I no longer do much if any PHP dev, I have moved on, mostly work in dotnet core, node.js &amp; golang these days. If anyone is keen to take over these projects, get in touch -

The Session Gear
================

[](#the-session-gear)

[![Build Status](https://camo.githubusercontent.com/2641487d017bb7795588ce63abd1f49db6ce91615da6484f98199d316698cfca/68747470733a2f2f7472617669732d63692e6f72672f70687067656172626f782f73657373696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpgearbox/session)[![Latest Stable Version](https://camo.githubusercontent.com/75bbada0600098cd236236330f7164c2fc44c4fde14bb3b3b5bc51251e502c87/68747470733a2f2f706f7365722e707567782e6f72672f67656172732f73657373696f6e2f762f737461626c652e737667)](https://packagist.org/packages/gears/session)[![Total Downloads](https://camo.githubusercontent.com/2425b3e3e6e8befe00fdfe1647c430938d3fcbaded93e75a1e333d955f611d3d/68747470733a2f2f706f7365722e707567782e6f72672f67656172732f73657373696f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/gears/session)[![License](https://camo.githubusercontent.com/0319491730ffddffaf451922017a37e4cc888f3da22aaf87b6ba9d121539190e/68747470733a2f2f706f7365722e707567782e6f72672f67656172732f73657373696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/gears/session)

**Laravel Sessions Standalone**

Okay so by now hopefully you have heard of [Laravel](http://laravel.com/), the PHP framework that just makes things easy. So first things first full credit goes to [Taylor Otwell](https://github.com/taylorotwell) for the Session API.

How to Install
--------------

[](#how-to-install)

Installation via composer is easy:

```
composer require gears/session:*

```

How to Use
----------

[](#how-to-use)

In your *legacy* - non Laravel application. You can use the Laravel Session API like so:

```
// Make sure you have composer included
require('vendor/autoload.php');

// Create a new gears session.
$session = new Gears\Session();

// Configure the session container
$session->dbConfig =
[
	'driver'    => 'mysql',
	'host'      => 'localhost',
	'database'  => 'db_name',
	'username'  => 'db_user',
	'password'  => 'abc123',
	'charset'   => 'utf8',
	'collation' => 'utf8_unicode_ci',
	'prefix'    => '',
];

// Install the session api
$session->install();

// Next you will probably want to make the session object global.
$session->globalise();
```

> NOTE: The dbConfig array must describe a valid db connection. This array is passed directly to $capsule-&gt;addConnection For more info on this see:
>
> -
> -

Now you can use code like the following:

```
// Storing An Item In The Session
Session::put('key', 'value');

// Push A Value Onto An Array Session Value
Session::push('user.teams', 'developers');

// Retrieving An Item From The Session
$value = Session::get('key');

// Retrieving An Item Or Returning A Default Value
$value = Session::get('key', 'default');
$value = Session::get('key', function() { return 'default'; });

// Retrieving An Item And Forgetting It
$value = Session::pull('key', 'default');

// Retrieving All Data From The Session
$data = Session::all();

// Determining If An Item Exists In The Session
if (Session::has('users'))
{
    //
}

// Removing An Item From The Session
Session::forget('key');

// Removing All Items From The Session
Session::flush();

// Regenerating The Session ID
Session::regenerate();

// Flashing Data
Session::flash('key', 'value');

// Reflashing The Current Flash Data For Another Request
Session::reflash();

// Reflashing Only A Subset Of Flash Data
Session::keep(array('username', 'email'));
```

For more info on the Session API it's self see:

*NOTE: While the Laravel Session API does provide support for many different drivers. This package only supports the database driver (for now).*

**WARINING: Do not use the built in native PHP session functions and / or the global $\_SESSION array**

Our Extra Method: hasExpired
----------------------------

[](#our-extra-method-hasexpired)

To my current knowledge of Laravel, there is no built in way to work out if a Session has been set but then expired. So in a normal Laravel app if you wanted to display a "Your Session has expired!" message you would need to do some custom filters or something... see:

But with *Gears\\Session* just call:

```
if (Session::hasExpired())
{
	echo 'Due to inactivity, your session has expired!';
	echo 'Please click here to login again.';
}
```

So now for the why?
-------------------

[](#so-now-for-the-why)

While laravel is so awesomely cool and great. If you want to pull a feature out and use it in another project it can become difficult. Firstly you have to have an innate understanding of the [IoC Container](http://laravel.com/docs/ioc).

You then find that this class needs that class which then requires some other config variable that is normally present in the IoC when run inside a normal Laravel App but in your case you haven't defined it and don't really want to define that value because it makes no sense in your lets say *legacy*application.

Perfect example is when I tried to pull the session API out to use in WordPress. It wanted to know about a `booted` method, which I think comes from `Illuminate\Foundation\Application`. At this point in time I already had to add various other things into the IoC to make it happy and it was the last straw that broke the camels back, I chucked a coders tantrum, walked to the fridge, grabbed another Redbull and sat back down with a new approach.

The result is this project.

---

Developed by Brad Jones -

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

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 ~3 days

Total

9

Last Release

4291d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2754772?v=4)[Brad Jones](/maintainers/brad-jones)[@brad-jones](https://github.com/brad-jones)

---

Top Contributors

[![brad-jones](https://avatars.githubusercontent.com/u/2754772?v=4)](https://github.com/brad-jones "brad-jones (11 commits)")

---

Tags

laravelstandalonesessions

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[flarum/core

Delightfully simple forum software.

201.4M2.3k](/packages/flarum-core)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)[offload-project/laravel-toggle

A simple and flexible feature toggle (feature flag) package for Laravel

251.6k](/packages/offload-project-laravel-toggle)

PHPackages © 2026

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