PHPackages                             phpcraftdream/figcookies - 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. phpcraftdream/figcookies

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

phpcraftdream/figcookies
========================

Cookies for PSR-7 HTTP Message Interface.

2.0.0(8y ago)024MITPHPPHP &gt;=7.1

Since Oct 13Pushed 8y ago1 watchersCompare

[ Source](https://github.com/PHPCraftdream/figcookies)[ Packagist](https://packagist.org/packages/phpcraftdream/figcookies)[ RSS](/packages/phpcraftdream-figcookies/feed)WikiDiscussions master Synced 2mo ago

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

FIG Cookies
===========

[](#fig-cookies)

Managing Cookies for PSR-7 Requests and Responses. It is fork from [dflydev/dflydev-fig-cookies](https://github.com/dflydev/dflydev-fig-cookies)

[![Build Status](https://camo.githubusercontent.com/a14e99d8fc5891cc9f53af1f2404601e4d8d7954d76fc0c935c8163874e91624/68747470733a2f2f6170692e7472617669732d63692e6f72672f5048504372616674647265616d2f666967636f6f6b6965732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/PHPCraftdream/figcookies)

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

[](#requirements)

- PHP 7.1+
- [psr/http-message](https://packagist.org/packages/psr/http-message)

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

[](#installation)

```
$> composer require phpcraftdream/figcookies
```

Concepts
--------

[](#concepts)

Instantiating these collections looks like this:

```
use PHPCraftdream\FigCookies\Cookies;

// Get cookies from request
$cookies = (new Cookies)->fromRequest($request);

// Get cookies from response
$cookies = (new Cookies)->fromResponse($response);
```

After modifying these collections in some way, they are rendered into a PSR-7 Request or PSR-7 Response like this:

```
// Render the Cookie headers and add them to the headers of a
// PSR-7 Request.
$request = $cookies->toRequest($request);

// Render the Set-Cookie headers and add them to the headers of a
// PSR-7 Response.
$response = $cookies->toResponse($response);
```

Basic Usage
-----------

[](#basic-usage)

#### Get a Request Cookie

[](#get-a-request-cookie)

The `get` method will return a `Cookie` instance. If no cookie by the specified name exists, the returned `Cookie` instance will have new empty `Cookie` instance.

```
use PHPCraftdream\FigCookies\Cookies;

$cookie = (new Cookies)->fromRequest($request)->get('theme');
$cookie->isNew(); //true if no cookie by the specified name exists
//...
$cookie->getValue();
```

#### Set a Request Cookie

[](#set-a-request-cookie)

The `set` method will either add a cookie or replace an existing cookie.

The `Cookie` primitive is used as the second argument.

```
use PHPCraftdream\FigCookies\Cookies;

$cookies = (new Cookies)->fromRequest($request);
$cookies->get('theme')->setValue('acme');

$request = $cookies->toRequest($request);
```

#### Remove a Request Cookie

[](#remove-a-request-cookie)

The `remove` method removes a cookie if it exists.

```
use PHPCraftdream\FigCookies\Cookies;

$cookies = (new Cookies)->fromRequest($request);
$cookies->delete('theme');
$request = $cookies->toRequest($request);
```

### Create cookie

[](#create-cookie)

```
use PHPCraftdream\FigCookies\Cookie;

$cookie = (new Cookie('lu'))
	->setValue('Rg3vHJZnehYLjVg7qi3bZjzg')
	->setExpires('Tue, 15-Jan-2013 21:47:38 GMT')
	->setMaxAge(500)
	->rememberForever()
	->setPath('/')
	->setDomain('.example.com')
	->setSecure(true)
	->setHttpOnly(true)
;
```

#### Get a Response Cookie

[](#get-a-response-cookie)

```
use PHPCraftdream\FigCookies\Cookies;

$cookies = (new Cookies)->fromResponse($response);
$cookie = $cookies->get('theme');
```

#### Set a Response Cookie

[](#set-a-response-cookie)

The `add` method will either add a cookie or replace an existing cookie.

```
use PHPCraftdream\FigCookies\Cookie;
use PHPCraftdream\FigCookies\Cookies;

$cookies = (new Cookies)->fromResponse($response);

$response = $cookies
	->add(
		(new Cookie('token'))
		->setValue('a9s87dfz978a9')
		->setDomain('example.com')
		->setPath('/firewall')
	)
	->toResponse($response);
```

#### Modify a Response Cookie

[](#modify-a-response-cookie)

```
use PHPCraftdream\FigCookies\Cookies;

$cookies = (new Cookies)->fromResponse($response);

$cookie = $cookies->get('visitCount');
$cookie->setValue($cookie->getValue() + 1);

$response = $cookies->toResponse($response);
```

#### Remove a Response Cookie

[](#remove-a-response-cookie)

The `delete` method removes a cookie from the response if it exists.

```
use PHPCraftdream\FigCookies\Cookies;

$response = (new Cookies)
				->fromResponse($response)
				->delete('theme')
				->toResponse($response);
```

#### Expire a Response Cookie

[](#expire-a-response-cookie)

The `expire` method sets a cookie with an expiry date in the far past. This causes the client to remove the cookie.

```
use PHPCraftdream\FigCookies\Cookies;

$cookies = (new Cookies)->fromResponse($response);
$cookies->get('session_cookie')->expire();
$response = $cookies->toResponse($response);
```

FAQ
---

[](#faq)

### Do you call `setcookies`?

[](#do-you-call-setcookies)

No.

Delivery of the rendered `Cookies` instances is the responsibility of the PSR-7 client implementation.

### Do you do anything with sessions?

[](#do-you-do-anything-with-sessions)

No.

It would be possible to build session handling using cookies on top of FIG Cookies but it is out of scope for this package.

### Do you read from `$_COOKIES`?

[](#do-you-read-from-_cookies)

No.

FIG Cookies only pays attention to the `Cookie` headers on PSR-7 Request instances.

License
-------

[](#license)

MIT, see LICENSE.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

3147d ago

Major Versions

1.0.0 → 2.0.02017-10-01

PHP version history (2 changes)1.0.0PHP &gt;=7.0

2.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3de650191edaf420b037ef898863f339945e39124b38fb738114223439a690f?d=identicon)[PHPCraftdream](/maintainers/PHPCraftdream)

---

Top Contributors

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

---

Tags

psr-7psr7cookiescookie

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpcraftdream-figcookies/health.svg)

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

###  Alternatives

[dflydev/fig-cookies

Cookies for PSR-7 HTTP Message Interface.

2268.5M102](/packages/dflydev-fig-cookies)[league/route

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

6633.1M115](/packages/league-route)[neomerx/cors-psr7

Framework agnostic (PSR-7) CORS implementation (www.w3.org/TR/cors/)

682.4M19](/packages/neomerx-cors-psr7)[amphp/http-client-cookies

Automatic cookie handling for Amp's HTTP client.

14750.8k12](/packages/amphp-http-client-cookies)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[wellrested/wellrested

Simple PHP Library for RESTful APIs

4818.7k4](/packages/wellrested-wellrested)

PHPackages © 2026

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