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)01202MITPHPPHP &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 1mo ago

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 43% 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

1123d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a7ef7750fdc43614c00e641939b148f999b2771b930cf3cf1b18c66fe614de9c?d=identicon)[symbiotic](/maintainers/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

[league/route

Fast routing and dispatch component including PSR-15 middleware, built on top of FastRoute.

6633.1M116](/packages/league-route)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[openswoole/core

Openswoole core library

181.1M32](/packages/openswoole-core)[wellrested/wellrested

Simple PHP Library for RESTful APIs

4818.7k4](/packages/wellrested-wellrested)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[selective/samesite-cookie

Secure your site with SameSite cookies

10144.0k](/packages/selective-samesite-cookie)

PHPackages © 2026

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