PHPackages                             phpgt/cookie - 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/cookie

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

phpgt/cookie
============

Object oriented cookie handler.

v1.0.3(1y ago)13.4k↓25%[4 PRs](https://github.com/PhpGt/Cookie/pulls)1MITPHPPHP &gt;=8.1CI passing

Since Jan 16Pushed 7mo ago1 watchersCompare

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

READMEChangelog (8)Dependencies (4)Versions (16)Used By (1)

Object oriented cookie handler.
-------------------------------

[](#object-oriented-cookie-handler)

This library is an object oriented alternative to the `$_COOKIE` superglobal that can be read using the same associative array style code. The `Cookie` class represents cookie data in immutable objects, meaning that the state of the request/response cookies cannot be accidentally changed by undisclosed areas of code.

---

[ ![Build status](https://camo.githubusercontent.com/cde676f95c6ad066b8ddaac98beb41ac792725aed95eb7886f1cda08b8903949/68747470733a2f2f62616467652e7374617475732e7068702e67742f636f6f6b69652d6275696c642e737667)](https://github.com/PhpGt/Cookie/actions)[ ![Code quality](https://camo.githubusercontent.com/67a07f3b0bbca82223b25b75c2ff45eca7c4f7c7ef92ca6d3fc05b3d5b2fae53/68747470733a2f2f62616467652e7374617475732e7068702e67742f636f6f6b69652d7175616c6974792e737667)](https://app.codacy.com/gh/PhpGt/Cookie)[ ![Code coverage](https://camo.githubusercontent.com/e47a6ab56f7b49882b04002e639305c1bbef148fa1db327e4876d31683b2b1df/68747470733a2f2f62616467652e7374617475732e7068702e67742f636f6f6b69652d636f7665726167652e737667)](https://app.codacy.com/gh/PhpGt/Cookie)[ ![Current version](https://camo.githubusercontent.com/84e6c116d792a15dcb3e2391d4ef2cf7be88d6fd66c2ba528b54d34afc9e8db6/68747470733a2f2f62616467652e7374617475732e7068702e67742f636f6f6b69652d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/Cookie)[ ![PHP.Gt/Cookie documentation](https://camo.githubusercontent.com/d3fc76a0bb694797b7139b0dbff54fb0aba2fd48852dd982d4b1cb634633fc17/68747470733a2f2f62616467652e7374617475732e7068702e67742f636f6f6b69652d646f63732e737667)](http://www.php.gt/cookie)Example usage
-------------

[](#example-usage)

```
// Create a replacement for $_COOKIE.
$cookie = new Gt\Cookie\CookieHandler($_COOKIE);

// Access values as normal.
$value = $cookie["firstVisit"];

if(isset($cookie["firstVisit"])) {
// Cookie "firstVisit" exists.
}

if($cookie->has("firstVisit")) {
// Cookie "firstVisit" exists.
}
else {
// Create a new cookie that expires in ten days.
	$now = new DateTime();
	$expire = new DateTime("+10 days");
	$cookie->set("firstVisit", $now, $expire);
}

// Now you can unset the superglobal!
```

What's not covered?
-------------------

[](#whats-not-covered)

This library does not touch on encrypting cookies. To store sensitive information across HTTP requests, use a session variable. To ensure cookies can't be read by JavaScript, use a secure HTTP-only cookie.

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

47

—

FairBetter than 94% of packages

Maintenance55

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 50.9% 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 ~372 days

Recently: every ~560 days

Total

8

Last Release

437d ago

Major Versions

v0.2.0 → v1.0.02019-01-18

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

v0.2.0PHP ^7.2

v1.0.2PHP &gt;=7.2

v1.0.3PHP &gt;=8.1

### 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] (27 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (21 commits)")[![g105b](https://avatars.githubusercontent.com/u/358014?v=4)](https://github.com/g105b "g105b (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

cookiecookiejarcookieshttpobject-orientedphp-cookiephpgt

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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