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

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

phpgt/session
=============

Encapsulated user sessions.

v1.2.5(6mo ago)17.7k—5.6%1[1 issues](https://github.com/PhpGt/Session/issues)[1 PRs](https://github.com/PhpGt/Session/pulls)4MITPHPPHP &gt;=8.2CI passing

Since Feb 20Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/PhpGt/Session)[ Packagist](https://packagist.org/packages/phpgt/session)[ GitHub Sponsors](https://github.com/sponsors/PhpGt)[ RSS](/packages/phpgt-session/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (31)Used By (4)

Encapsulated user sessions.
===========================

[](#encapsulated-user-sessions)

This library is a simple object oriented alternative to the $\_SESSION superglobal allowing application code to be passed encapsulated `SessionStore` objects, so areas of code can have access to their own Session area without having full read-write access to all session variables.

Sessions are addressed using dot notation, allowing for handling categories of session data. This is particularly useful when dealing with user authentication, for example.

---

[ ![Build status](https://camo.githubusercontent.com/20fddb41c6550c1bbb6da59817b8950491607f0967d32c7e2c4cd220334b094e/68747470733a2f2f62616467652e7374617475732e7068702e67742f73657373696f6e2d6275696c642e737667)](https://github.com/PhpGt/Session/actions)[ ![Code quality](https://camo.githubusercontent.com/1fdc613ec49ecaee948dc2af889396d101e4c217ba46d99e8bb3989a4d177ed5/68747470733a2f2f62616467652e7374617475732e7068702e67742f73657373696f6e2d7175616c6974792e737667)](https://app.codacy.com/gh/PhpGt/Session)[ ![Code coverage](https://camo.githubusercontent.com/5101c78f7539f47d2b5e1df20d14dd779c7091a06b95489a4b97831c145c18cf/68747470733a2f2f62616467652e7374617475732e7068702e67742f73657373696f6e2d636f7665726167652e737667)](https://app.codecov.io/gh/PhpGt/Session)[ ![Current version](https://camo.githubusercontent.com/99e75758ff60990e5f32cfc2371ae8703b8a4d523f1f7689cf544a629a614c02/68747470733a2f2f62616467652e7374617475732e7068702e67742f73657373696f6e2d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/Session)[ ![PHP.Gt/Session documentation](https://camo.githubusercontent.com/61a80b68e920a562a525f5153df88ee81a4d2dd9e5864a854f2fd933701bbf1b/68747470733a2f2f62616467652e7374617475732e7068702e67742f73657373696f6e2d646f63732e737667)](http://www.php.gt/session)Example usage: Welcome a user by their first name or log out the user
---------------------------------------------------------------------

[](#example-usage-welcome-a-user-by-their-first-name-or-log-out-the-user)

```
if($session->contains("auth")) {
// Remove the *whole* auth section of the session on logout.
	if($action === "logout") {
		$session->delete("auth");
	}
	else {
// Output a variable within the auth namespace:
		$message = "Welcome back, " . $session->getString("auth.user.name");
	}
}
else {
// Pass the "auth" store to a class, so it
// can't read/write to other session variables:
	AuthenticationSystem::beginLogin($session->getStore("auth"));
}
```

Redis session storage
---------------------

[](#redis-session-storage)

This package now includes `Gt\Session\RedisHandler` for shared session storage. It works with Redis-compatible backends such as Redis and Valkey, and is intended for deployments where application nodes are disposable and session state needs to survive traffic moving between servers.

`RedisHandler` expects `save_path` to be a DSN rather than a filesystem path. It uses the `phpredis` extension at runtime.

Example production config:

```
[session]
handler=Gt\Session\RedisHandler
save_path=rediss://default:secret@example-redis.internal:25061/0?prefix=GT:&ttl=1440
name=GT
use_cookies=true
```

Supported DSN forms:

- `redis://host:6379`
- `redis://:password@host:6379/0`
- `redis://username:password@host:6379/0`
- `rediss://username:password@host:6379/0`

Useful query parameters:

- `prefix`: key prefix for stored sessions, defaults to `:`
- `ttl`: session lifetime in seconds, defaults to `session.gc_maxlifetime`
- `timeout`: connection timeout in seconds
- `read_timeout`: socket read timeout in seconds
- `persistent=1`: enable persistent connections
- `persistent_id`: optional persistent connection pool id
- `verify_peer=0` / `verify_peer_name=0`: optional TLS verification flags

Proudly sponsored by
====================

[](#proudly-sponsored-by)

[JetBrains Open Source sponsorship program](https://www.jetbrains.com/community/opensource/)

[![JetBrains logo.](https://camo.githubusercontent.com/b5639e7738c6dfae9fe3f3e20175570b7376ce2577a772e09c25c2d4f14bf86e/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a6574627261696e732e737667)](https://www.jetbrains.com/community/opensource/)

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance58

Moderate activity, may be stable

Popularity27

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~222 days

Total

21

Last Release

199d ago

Major Versions

v0.2.3 → v1.0.02019-06-10

PHP version history (5 changes)v0.0.1PHP ^7.1

v0.2.2PHP &gt;=7.2

v1.1.4PHP &gt;=8.0

v1.2.2PHP &gt;=8.1

v1.2.4PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e42344b91ce4b91ab57875969f67a0a6a48de570a08bc65d673b06b72fd3a3f?d=identicon)[g105b](/maintainers/g105b)

---

Top Contributors

[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (29 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (23 commits)")[![g105b](https://avatars.githubusercontent.com/u/358014?v=4)](https://github.com/g105b "g105b (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

cookiephpgtsession-cookiesession-handlersession-managementsessionstorage

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[simple-updates/phpwhois

This package contains a Whois (RFC954) library for PHP. It allows a PHP program to create a Whois object, and obtain the output of a whois query with the Lookup function.

251.4k](/packages/simple-updates-phpwhois)

PHPackages © 2026

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