PHPackages                             bag2/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. bag2/cookie

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

bag2/cookie
===========

Cookie functions over PSR-7 and setcookie() function.

v0.9.0(6mo ago)1711.8k↑33.6%1[1 PRs](https://github.com/bag2php/cookie/pulls)Apache-2.0PHPPHP &gt;=8.1

Since Jan 12Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/bag2php/cookie)[ Packagist](https://packagist.org/packages/bag2/cookie)[ Fund](https://www.pixiv.net/fanbox/creator/105589)[ GitHub Sponsors](https://github.com/zonuexe)[ RSS](/packages/bag2-cookie/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (9)Versions (19)Used By (0)

Bag2\\Cookie
============

[](#bag2cookie)

[![Packagist Version](https://camo.githubusercontent.com/0bd4dc412b533e862a02f8171346effa7b0f4d9831ee3fdfe891866400093af6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626167322f636f6f6b69653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/0bd4dc412b533e862a02f8171346effa7b0f4d9831ee3fdfe891866400093af6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626167322f636f6f6b69653f7374796c653d666c61742d737175617265)[![PHP from Packagist](https://camo.githubusercontent.com/c5cd026af1d3007dc8e821e6c4c0b3ea48482d3ecf7ab596510ec7410b414668/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f626167322f636f6f6b69653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/c5cd026af1d3007dc8e821e6c4c0b3ea48482d3ecf7ab596510ec7410b414668/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f626167322f636f6f6b69653f7374796c653d666c61742d737175617265)[![Packagist](https://camo.githubusercontent.com/017172d25950d9a386753349b66679c814546166d4d8e7670f803d820501e9a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626167322f636f6f6b69653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/017172d25950d9a386753349b66679c814546166d4d8e7670f803d820501e9a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626167322f636f6f6b69653f7374796c653d666c61742d737175617265)

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

[](#installation)

```
composer require bag2/cookie

```

Motivation
----------

[](#motivation)

We have some problems with HTTP `Set-Cookie` response header in PHP.

- PHP's `setcookie()` function started supporting ['SameSite' cookie attribute](https://caniuse.com/#feat=same-site-cookie-attribute) from 7.3.0
- Sending `SameSite` cookies under PHP 7.3.0 requires an unusual hack
- PSR-7 does not provide high-level functions for Cookies
- The `setcookie()` function is useless for the era of PSR-7

This package provides common features whether your project is **PSR-7 based** or **vanilla PHP** (direct call to `setcookie()` function).

Examples
--------

[](#examples)

### Create Cookie Oven

[](#create-cookie-oven)

**`Oven`** is an object that can hold multiple `Set-Cookie` entries. Use `CookieOvenBuilder` to create an `Oven` object. The value specified in the constructor or the "with" method builds the default value for the option added to the `Set-Cookie`.

```
