Skip to content
Cookie management for PHP
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src
tests
.gitignore
LICENSE
README.md
composer.json
phpcs.xml
phpunit.xml.dist

README.md

Cookie Manager

PHP package that allows you to comfortably manage cookies.

This package requires PHP version 7.2 or later.

Support:

  • storing cookies loaded from a request separately from cookies sends in response

  • sending all cookies in response at the same time

  • validating that the cookies is not tampered with

  • customizing that allows you to create your own cookie manager and data hasher

Installation

This library is installed using the composer:

composer require devanych/cookie-manager

Basic usage

Create cookie manager:

use Devanych\Cookie\CookieManager;
use Devanych\Cookie\Cookie;

// Without the use of cookie validation
$cookieManager = new CookieManager();

// With the use of cookie validation
$cookieManager = new CookieManager(true, '0m1oxVkjCJnD_qi3r4lUxcAdpDlMIwiS');

Actions with cookie:

// Loads the cookies from the request
$cookieManager->load();

// Gets the load cookie
$cookie = $cookieManager->getLoadCookies()->get('cookie_name');

// Sets new time expires
$cookie->setExpire(time() + 3600);

// Adds a cookie to the sending
$cookieManager->getSendCookies()->add($cookie);

// Adds a new cookie to the sending
$cookieManager->getSendCookies()->add(new Cookie('new_cookie_1', 'cookie_value_1'));
$cookieManager->getSendCookies()->add(new Cookie('new_cookie_2', 'cookie_value_2', time() + 3600));

// Sends the cookies to the response.
$cookieManager->send();

Documentation

  • Source files of the documentation are here.
You can’t perform that action at this time.