httpsoft/http-cookie

Managing cookies with PSR-7 support

Maintainers

👁 devanych

Package info

github.com/httpsoft/http-cookie

Homepage

Documentation

pkg:composer/httpsoft/http-cookie

Statistics

Installs: 156 076

Dependents: 4

Suggesters: 0

Stars: 3

Open Issues: 0

1.1.0 2023-05-05 20:37 UTC

Requires

Suggests

None

Conflicts

None

Replaces

None

MIT c304b7d9888ed27bf2bcdb95762d87263a457644

phphttpcookiescookiepsr-7psr-15http-cookie

This package is auto-updated.

Last update: 2026-06-29 02:00:25 UTC


README

👁 License
👁 Latest Stable Version
👁 Total Downloads
👁 GitHub Build Status
👁 GitHub Static Analysis Status
👁 Scrutinizer Code Coverage
👁 Scrutinizer Code Quality

This package provides convenient cookie management in accordance with the RFC 6265 specification.

This package supports PSR-7 and PSR-15 interfaces.

Documentation

Installation

This package requires PHP version 7.4 or later.

composer require httpsoft/http-cookie

Usage

use HttpSoft\Cookie\Cookie;
use HttpSoft\Cookie\CookieCreator;
use HttpSoft\Cookie\CookieManager;
use HttpSoft\Cookie\CookieSendMiddleware;

/**
 * @var Psr\Http\Message\ResponseInterface $response
 * @var Psr\Http\Message\ServerRequestInterface $request
 * @var Psr\Http\Server\RequestHandlerInterface $handler
 */
 
$manager = new CookieManager();

// Create cookie
$cookie1 = new Cookie('test', 'value', '+1 hour');
// or
$cookie2 = CookieCreator::create('test2', 'value', time() + 3600, '.example.com', '/path');
// or from raw `Set-Cookie` header
$cookie3 = CookieCreator::createFromString('name=value; Path=/; Secure; HttpOnly; SameSite=Lax; ...');

// Set cookies to the manager
$manager->set($cookie1);
$manager->set($cookie2);
$manager->set($cookie3);

// Set all cookie to the response for sending
$response = $manager->send($response);
// or use `CookieSendMiddleware` middleware
$middleware = new CookieSendMiddleware($manager);
$response = $middleware->process($request, $handler);

// Emit a response to the client
// ...