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

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

symbiotic/http-cookie
=====================

Slim (10Kb) implementation of working with cookies, with psr-15 middleware, without dependencies (psr interfaces only).

1.4.2(3y ago)01212MITPHPPHP &gt;=8.0

Since Sep 11Pushed 3y agoCompare

[ Source](https://github.com/symbiotic-php/http-cookie)[ Packagist](https://packagist.org/packages/symbiotic/http-cookie)[ RSS](/packages/symbiotic-http-cookie/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (4)Versions (4)Used By (2)

Symbiotic Http Cookie
=====================

[](#symbiotic-http-cookie)

README.RU.md [РУССКОЕ ОПИСАНИЕ](https://github.com/Symbiotic-php/http-cookie/blob/master/README.RU.md)

Features
--------

[](#features)

- Accepts basic settings for installing cookies (domain, path, secure, expires, etc.)
- No extra code and very light (9 Kb)
- Compatible with PSR-15, PSR-7
- Included PSR-15 Cookie Middleware
- Has no dependencies, only PSR interfaces
- You can work as with an array (ArrayAccess)
- Нет приватных свойств и методов

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

[](#installation)

```
composer require symbiotic/http-cookie

```

Using
-----

[](#using)

For easier operation, the package has a ready-made PSR-15 Middleware, which itself will accept cookies from the request and send them in response:

\\Symbiotic\\Http\\Cookie\\CookiesMiddleware

##### Initialization

[](#initialization)

```
$cookies = new \Symbiotic\Http\Cookie\Cookies();

// Setting default values
$domain  = 'example.com';
$path    = '/';
$expires = time() + (3600 * 24 * 365);
$secure = true; // only https
// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes
$same_site = \Symbiotic\Http\Cookie\CookiesInterface::SAMESITE_LAX;

$cookies->setDefaults($domain, $path, $expires, $secure, $same_site);

/**
 * Installing cookies from a request with the ServerRequestInterface
 *
 * @var \Psr\Http\Message\ServerRequestInterface $request
 * @var string[] $request_cookies ['name' => 'value',...]
**/
$request_cookies = $request->getCookieParams();
$cookies->setRequestCookies($request_cookies);

/**
 * Or native
 **/
$cookies->setRequestCookies($_COOKIE);
```

##### Getting and checking availability

[](#getting-and-checking-availability)

```
$cookies = new Symbiotic\Http\Cookie\Cookies();

/**
 * Checking for the presence of a cookie from the request, a cookie with an empty value also exists
 */
$cookies->has('cookie_name'); // return bool

/**
 * Getting cookie by name
 * If the cookie does not exist it will return null
**/
$cookies->get('cookie_name'); // return string or null

/**
 * Getting a cookie with a default value, if the cookie does not exist.
**/
$cookies->get('cookie_name', 'default_value'); // return string
```

##### Setting the response cookie

[](#setting-the-response-cookie)

```
$cookies = new \Symbiotic\Http\Cookie\Cookies();

/**
 * Short way to add cookies
 * the remaining parameters are taken from the default values set in the method:
 * @see \Symbiotic\Http\Cookie\Cookies::setDefaults()
 */
$cookies->set('cookie_name', 'cookie value');

/**
 * Advanced installation method, allows you to pass any parameters
 * if you pass null to some parameters, they will be taken from the default ones
 */
$domain  = 'www.example.com';
$path    = '/docs';
$expires = time()+300; // timestamp for 5 minutes ahead
$secure = false; // only https
$http_only = true; // only http request access
// advanced params
$options = [
    'same_site' => \Symbiotic\Http\Cookie\CookiesInterface::SAMESITE_STRICT,
    'max_age' =>1000
];

$cookies->setCookie('cookie_name', 'cookie value', $expires, $http_only, $path, $domain, $secure, $options);
```

##### Deleting cookies

[](#deleting-cookies)

```
$cookies = new \Symbiotic\Http\Cookie\Cookies();

/**
 * Short way to delete cookies
 * the remaining parameters are taken from the default values set in the method:
 * @see \Symbiotic\Http\Cookie\Cookies::setDefaults()
 */
$cookies->remove('cookie_name');

/**
 * Deleting multiple cookies at once
 */
$delete_cookies = [
    'name1',
    'name2',
    'name3'
];
$cookies->remove($delete_cookies);

/**
 * Advanced deletion method, allows you to pass any parameters
 * if you pass null to some parameters, they will be taken from the default ones
 */
$domain  = 'www.example.com';
$path    = '/docs';
$expires =  time()-(60*60*48); // outdated timestamp!!!
$cookies->setCookie('cookie_name', '', $expires, null, $path, $domain);
```

### Working as with an array (ArrayAccess)

[](#working-as-with-an-array-arrayaccess)

For easier data access and easier cookie installation, the class implements the \\ArrayAccess interface.

```
$cookies = new \Symbiotic\Http\Cookie\Cookies();

/**
 * Getting a cookie from a request
 * @see \Symbiotic\Http\Cookie\Cookies::get($key)
 */
$value = $cookies['cookie_name']; // string|array or null if not exists

/**
 * Setting a cookie in response
 * (the domain and other parameters are taken from the default ones)
 * @see \Symbiotic\Http\Cookie\Cookies::set($key, $value)
 */
$cookies['new_cookie'] = 'value';

/**
 * Checking the existence of a cookie from a request
 * @see \Symbiotic\Http\Cookie\Cookies::has($key)
 */
$exists  = isset($cookies['new_cookie']);

/**
 * Delete cookie
 * @see \Symbiotic\Http\Cookie\Cookies::remove($key)
 */
unset($cookies['cookie_name']);
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

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

Total

3

Last Release

1178d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5098237?v=4)[symbiotic](/maintainers/symbiotic)[@symbiotic](https://github.com/symbiotic)

---

Top Contributors

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

---

Tags

cookiepsr15psr7 cookiecookie middlewaresymbiotic

### Embed Badge

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

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[cakephp/authentication

Authentication plugin for CakePHP

1214.1M106](/packages/cakephp-authentication)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.1k](/packages/typo3-cms-core)[sunrise/http-router

A powerful solution as the foundation of your project.

17451.6k10](/packages/sunrise-http-router)[typo3/cms-adminpanel

TYPO3 CMS Admin Panel - The Admin Panel displays information about your site in the frontend and contains a range of metrics including debug and caching information.

115.7M66](/packages/typo3-cms-adminpanel)

PHPackages © 2026

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