PHPackages                             commandstring/reactphp-cookies - 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. commandstring/reactphp-cookies

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

commandstring/reactphp-cookies
==============================

A simpler way to manipulate cookies in React/Http

v1.0.1(3y ago)127MITPHPPHP &gt;=8.1

Since Jan 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/CommandString/ReactPHP-Cookies)[ Packagist](https://packagist.org/packages/commandstring/reactphp-cookies)[ RSS](/packages/commandstring-reactphp-cookies/feed)WikiDiscussions main Synced 1mo ago

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

[CommandString/ReactPHP-cookies](https://packagist.org/packages/commandstring/reactphp-cookies) - A easier way to manipulate cookies in React/Http
==================================================================================================================================================

[](#commandstringreactphp-cookies---a-easier-way-to-manipulate-cookies-in-reacthttp)

### Install with Composer using `composer require commandstring/reactphp-cookies`

[](#install-with-composer-using-composer-require-commandstringreactphp-cookies)

*For the examples $req is an object that implements of PSR-7 ServerRequestInterface and $res is an object that implements PSR-7 ResponseInterface*

Creating Controller
===================

[](#creating-controller)

```
$cookieController = new CookieController(null);
```

If you want to encrypt your cookies you can either create a class that implements CookieEncryptionInterface or use [Cookie Encryption](https://github.com/CommandString/Cookie-Encryption)

Creating Cookie object from controller

You will need to create an object that implements PSR-7's Response Interface beforehand

```
$cookie = $cookieController->cookie($req, $res);
```

Setting cookies
===============

[](#setting-cookies)

```
$cookie->set("token", "123456", 1, 15, 13, "/app", "app.domain.com");
```

This will create a cookie with the name of `token` that is set to `123456`. This cookie will expire in 1 hour, 15 minutes, and 13 seconds from now. The cookie is valid only in the app path and on the app.domain.com website.

Getting cookies
===============

[](#getting-cookies)

```
$cookie->get("token");
```

If a cookie with the name of token is set then it will return it's value. If not it returns null.

Deleting cookies
================

[](#deleting-cookies)

```
$cookie->delete("token", "/app", "app.domain.com");
```

This will delete a cookie with the name token that has its path set to `/app` and domain set to `app.domain.com`

Example usage
=============

[](#example-usage)

```
