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

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

horizom/session
===============

The Horizom Session package.

3.1.0(3y ago)1142MITPHPPHP ^8.0

Since Jul 10Pushed 3y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (0)

[![](https://camo.githubusercontent.com/62380dbb63cdb97c3cb0d517f9a7b32b85320f06b0671ec5be2d3be4d9b16b01/68747470733a2f2f686f72697a6f6d2e6769746875622e696f2f696d672f686f72697a6f6d2d6c6f676f2d636f6c6f722e737667)](https://camo.githubusercontent.com/62380dbb63cdb97c3cb0d517f9a7b32b85320f06b0671ec5be2d3be4d9b16b01/68747470733a2f2f686f72697a6f6d2e6769746875622e696f2f696d672f686f72697a6f6d2d6c6f676f2d636f6c6f722e737667)

[![Total Downloads](https://camo.githubusercontent.com/e93740a8ce4d3c773fb81371e208720270be95716b69f1e6b0c71dfba4270a3a/68747470733a2f2f706f7365722e707567782e6f72672f686f72697a6f6d2f73657373696f6e2f642f746f74616c2e737667)](https://packagist.org/packages/horizom/session)[![Latest Stable Version](https://camo.githubusercontent.com/66b6f179c06973afd04c73136ce3ebf091ff2f1f5531f17647aa1c25fa328965/68747470733a2f2f706f7365722e707567782e6f72672f686f72697a6f6d2f73657373696f6e2f762f737461626c652e737667)](https://packagist.org/packages/horizom/session)[![License](https://camo.githubusercontent.com/ab11feda33a1b9f01b7f67dd518b2754b3e91414e7da04be9d5a42a106301e91/68747470733a2f2f706f7365722e707567782e6f72672f686f72697a6f6d2f73657373696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/horizom/session)

Horizom Session
===============

[](#horizom-session)

PHP library for handling sessions.

- [Requirements](#requirements)
- [Installation](#installation)
- [Available Methods](#available-methods)
- [Quick Start](#quick-start)
- [Usage](#usage)
- [Tests](#tests)
- [TODO](#todo)
- [Changelog](#changelog)
- [Contribution](#contribution)
- [Sponsor](#Sponsor)
- [License](#license)

---

Requirements
------------

[](#requirements)

This library is compatible with the PHP versions: 8.0 | 8.1.

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

[](#installation)

The preferred way to install this extension is through [Composer](http://getcomposer.org/download/).

To install **PHP Session library**, simply:

```
composer require horizom/session
```

The previous command will only install the necessary files, if you prefer to **download the entire source code** you can use:

```
composer require horizom/session --prefer-source
```

Available Methods
-----------------

[](#available-methods)

Available methods in this library:

### Starts the session

[](#starts-the-session)

```
$session->start(array $options = []);
```

**@see** for List of available `$options` and their default values

**@throws** `SessionException` If headers already sent

**@throws** `SessionException` If session already started

**@throws** `SessionException` If setting options failed

**@Return** `bool`

### Check if the session is started

[](#check-if-the-session-is-started)

```
$session->isStarted();
```

**@Return** `bool`

### Sets an attribute by name

[](#sets-an-attribute-by-name)

```
$session->set(string $name, mixed $value = null);
```

**@throws** `SessionException` If session is unstarted

**@Return** `void`

### Gets an attribute by name

[](#gets-an-attribute-by-name)

Optionally defines a default value when the attribute does not exist.

```
$session->get(string $name, mixed $default = null);
```

**@Return** `mixed` Value

### Gets all attributes

[](#gets-all-attributes)

```
$session->all();
```

**@Return** `array` $\_SESSION content

### Check if an attribute exists in the session

[](#check-if-an-attribute-exists-in-the-session)

```
$session->has(string $name);
```

**@Return** `bool`

### Sets several attributes at once

[](#sets-several-attributes-at-once)

If attributes exist they are replaced, if they do not exist they are created.

```
$session->replace(array $data);
```

**@throws** `SessionException` If session is unstarted

**@Return** `void`

### Deletes an attribute by name and returns its value

[](#deletes-an-attribute-by-name-and-returns-its-value)

Optionally defines a default value when the attribute does not exist.

```
$session->pull(string $name, mixed $default = null);
```

**@throws** `SessionException` If session is unstarted

**@Return** `mixed` Attribute value

### Deletes an attribute by name

[](#deletes-an-attribute-by-name)

```
$session->remove(string $name);
```

**@throws** `SessionException` If session is unstarted

**@Return** `void`

### Free all session variables

[](#free-all-session-variables)

```
$session->clear();
```

**@throws** `SessionException` If session is unstarted

**@Return** `void`

### Gets the session ID

[](#gets-the-session-id)

```
$session->getId();
```

**@Return** `string` Session ID

### Sets the session ID

[](#sets-the-session-id)

```
$session->setId(string $sessionId);
```

**@throws** `SessionException` If session already started

**@Return** `void`

### Update the current session id with a newly generated one

[](#update-the-current-session-id-with-a-newly-generated-one)

```
$session->regenerateId(bool $deleteOldSession = false);
```

**@throws** `SessionException` If session is unstarted

**@Return** `bool`

### Gets the session name

[](#gets-the-session-name)

```
$session->getName();
```

**@Return** `string` Session name

### Sets the session name

[](#sets-the-session-name)

```
$session->setName(string $name);
```

**@throws** `SessionException` If session already started

**@Return** `void`

### Destroys the session

[](#destroys-the-session)

```
$session->destroy();
```

**@throws** `SessionException` If session is unstarted

**@Return** `bool`

Quick Start
-----------

[](#quick-start)

To use this library with **Composer**:

```
use Horizom\Session\Session;

$session = new Session();
```

Or instead you can use a facade to access the methods statically:

```
use Horizom\Session\Facades\Session;
```

Usage
-----

[](#usage)

Example of use for this library:

### - Starts the session

[](#--starts-the-session)

Without setting options:

```
$session->start();
```

Setting options:

```
$session->start([
    // 'cache_expire' => 180,
    // 'cache_limiter' => 'nocache',
    // 'cookie_domain' => '',
    'cookie_httponly' => true,
    'cookie_lifetime' => 8000,
    // 'cookie_path' => '/',
    'cookie_samesite' => 'Strict',
    'cookie_secure'   => true,
    // 'gc_divisor' => 100,
    // 'gc_maxlifetime' => 1440,
    // 'gc_probability' => true,
    // 'lazy_write' => true,
    // 'name' => 'PHPSESSID',
    // 'read_and_close' => false,
    // 'referer_check' => '',
    // 'save_handler' => 'files',
    // 'save_path' => '',
    // 'serialize_handler' => 'php',
    // 'sid_bits_per_character' => 4,
    // 'sid_length' => 32,
    // 'trans_sid_hosts' => $_SERVER['HTTP_HOST'],
    // 'trans_sid_tags' => 'a=href,area=href,frame=src,form=',
    // 'use_cookies' => true,
    // 'use_only_cookies' => true,
    // 'use_strict_mode' => false,
    // 'use_trans_sid' => false,
]);
```

Using the facade:

```
Session::start();
```

### - Check if the session is started

[](#--check-if-the-session-is-started)

Using session object:

```
$session->isStarted();
```

Using the facade:

```
Session::isStarted();
```

### - Sets an attribute by name

[](#--sets-an-attribute-by-name)

Using session object:

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

Using the facade:

```
Session::set('foo', 'bar');
```

### - Gets an attribute by name

[](#--gets-an-attribute-by-name)

Without default value if attribute does not exist:

```
$session->get('foo'); // null if attribute does not exist
```

With default value if attribute does not exist:

```
$session->get('foo', false); // false if attribute does not exist
```

Using the facade:

```
Session::get('foo');
```

### - Gets all attributes

[](#--gets-all-attributes)

Using session object:

```
$session->all();
```

Using the facade:

```
Session::all();
```

### - Check if an attribute exists in the session

[](#--check-if-an-attribute-exists-in-the-session)

Using session object:

```
$session->has('foo');
```

Using the facade:

```
Session::has('foo');
```

### - Sets several attributes at once

[](#--sets-several-attributes-at-once)

Using session object:

```
$session->replace(['foo' => 'bar', 'bar' => 'foo']);
```

Using the facade:

```
Session::replace(['foo' => 'bar', 'bar' => 'foo']);
```

### - Deletes an attribute by name and returns its value

[](#--deletes-an-attribute-by-name-and-returns-its-value)

Without default value if attribute does not exist:

```
$session->pull('foo'); // null if attribute does not exist
```

With default value if attribute does not exist:

```
$session->pull('foo', false); // false if attribute does not exist
```

Using the facade:

```
Session::pull('foo');
```

### - Deletes an attribute by name

[](#--deletes-an-attribute-by-name)

Using session object:

```
$session->remove('foo');
```

Using the facade:

```
Session::remove('foo');
```

### - Free all session variables

[](#--free-all-session-variables)

Using session object:

```
$session->clear();
```

Using the facade:

```
Session::clear();
```

### - Gets the session ID

[](#--gets-the-session-id)

Using session object:

```
$session->getId();
```

Using the facade:

```
Session::getId();
```

### - Sets the session ID

[](#--sets-the-session-id)

Using session object:

```
$session->setId('foo');
```

Using the facade:

```
Session::setId('foo');
```

### - Update the current session id with a newly generated one

[](#--update-the-current-session-id-with-a-newly-generated-one)

Regenerate ID without deleting the old session:

```
$session->regenerateId();
```

Regenerate ID by deleting the old session:

```
$session->regenerateId(true);
```

Using the facade:

```
Session::regenerateId();
```

### - Gets the session name

[](#--gets-the-session-name)

Using session object:

```
$session->getName();
```

Using the facade:

```
Session::getName();
```

### - Sets the session name

[](#--sets-the-session-name)

Using session object:

```
$session->setName('foo');
```

Using the facade:

```
Session::setName('foo');
```

### - Destroys the session

[](#--destroys-the-session)

Using session object:

```
$session->destroy();
```

Using the facade:

```
Session::destroy();
```

License
-------

[](#license)

This repository is licensed under the [MIT License](LICENSE).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Total

2

Last Release

1408d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/412f8e786e65f078584b4bc2c0b7a44af095ab2c0d19a5fb7985598576ca4fda?d=identicon)[lambirou](/maintainers/lambirou)

---

Top Contributors

[![lambirou](https://avatars.githubusercontent.com/u/1428556?v=4)](https://github.com/lambirou "lambirou (1 commits)")

---

Tags

phpsessionhorizonhorizom

### Embed Badge

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

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

###  Alternatives

[rcastera/session

Session Class

222.2k](/packages/rcastera-session)

PHPackages © 2026

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