PHPackages                             mrclay/userland-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. [HTTP &amp; Networking](/categories/http)
4. /
5. mrclay/userland-session

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mrclay/userland-session
=======================

Provides a an HTTP cookie-based session in plain PHP, allowing concurrent use with existing native sessions.

3.0.0(11y ago)660.6k↓30.7%11MITPHPPHP &gt;=5.3.0

Since Mar 10Pushed 11mo ago2 watchersCompare

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

READMEChangelogDependencies (1)Versions (6)Used By (1)

UserlandSession
===============

[](#userlandsession)

[![https://travis-ci.org/mrclay/UserlandSession.png?branch=master](https://camo.githubusercontent.com/d37bfd7e4c111667a9398defc471554f12bb3e2799579d05f8229d94e4a6342e/68747470733a2f2f7472617669732d63692e6f72672f6d72636c61792f557365726c616e6453657373696f6e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/mrclay/UserlandSession)UserlandSession is an HTTP cookie-based session components implemented in plain PHP, allowing it to be used concurrently with--and completely independent of--existing native sessions. This makes it handy for bridging session state across multiple PHP apps with incompatible sessions.

- Loosely-coupled components that introduce no global state (except headers)
- Uses PHP's SessionHandlerInterface, so you can re-use existing 3rd-party handlers
- Session data is only accessible via the object instead of a global

```
// create a files-based session, directory sniffed from session.save_path
$session = \UserlandSession\SessionBuilder::instance()->build();
$session->start();

// use public $session->data array property...
$session->data['foo'] = 'bar';

// ...or use set/get()
$session->set('foo', 'bar');

$session->writeClose(); // ...or let destructor do this
```

Handlers
--------

[](#handlers)

The save handler interface is PHP's SessionHandlerInterface, and handlers FileHandler and PdoHandler are included.

Feel free to use your own save handler class, or use these as handlers for native sessions!

Creating a Session
------------------

[](#creating-a-session)

Easy ways to get a files-based session:

```
// from script (save path sniffed from session.save_path)
$session = (require 'path/to/UserlandSession/scripts/get_file_session.php');

// using builder (here we set the session name to MYSESS)
$session = SessionBuilder::instance()
    ->setSavePath('/tmp')
    ->setName('MYSESS')
    ->build();
```

File Storage Options
--------------------

[](#file-storage-options)

```
// turn off file locking
$session = SessionBuilder::instance()
    ->setFileLocking(false)
    ->build();
```

Using PDO
---------

[](#using-pdo)

```
// pre-existing PDO connection
$session = SessionBuilder::instance()
    ->setPdo($myConnection)
    ->setTable('userland_sessions')
    ->build();

// or if you want it to connect for you when needed:
$session = SessionBuilder::instance()
    ->setDbCredentials(array(
        'dsn' => 'mysql:host=localhost;dbname=ulsess;charset=UTF8',
        'username' => 'fred',
        'password' => 'password1',
    ))
    ->setTable('userland_sessions')
    ->build();
```

Extras
------

[](#extras)

You can check for data matching the client's cookie without starting the session:

```
if ($session->sessionLikelyExists()) {
    $session->start();
    // use session
} else {
    // don't start if we don't need to
}
```

Simpler cookie removal:

```
$session->removeCookie();

// or specify true when destroying the session
$session->destroy(true);
```

License
-------

[](#license)

MIT. See LICENSE.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

5

Last Release

4377d ago

Major Versions

1.x-dev → 2.0.02014-03-10

2.1.0 → 3.0.02014-05-25

### Community

Maintainers

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

---

Top Contributors

[![mrclay](https://avatars.githubusercontent.com/u/170687?v=4)](https://github.com/mrclay "mrclay (74 commits)")

---

Tags

httpSSOsingle sign onsession

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[league/uri

URI manipulation library

1.1k206.4M277](/packages/league-uri)[nette/http

🌐 Nette Http: abstraction for HTTP request, response and session. Provides careful data sanitization and utility for URL and cookies manipulation.

48819.2M541](/packages/nette-http)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

536204.9M23](/packages/league-uri-interfaces)[aplus/app

Aplus Framework App Project

5951.6M1](/packages/aplus-app)

PHPackages © 2026

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