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

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

rafaeldms/cookie
================

A simple component way to work with Cookies

1.1.1(3y ago)0135MITPHPPHP &gt;=8.0

Since Jul 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/rafaeldms/cookie)[ Packagist](https://packagist.org/packages/rafaeldms/cookie)[ Docs](https://www.cagep.com.br)[ RSS](/packages/rafaeldms-cookie/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (9)Used By (0)

Cookie @RafaelDms
=================

[](#cookie-rafaeldms)

[![Maintainer](https://camo.githubusercontent.com/18852872d1a978608104b9ddb3429f394991545e884ca42d2d4459e0af469558/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65722d4072616661656c646d732d626c75652e7376673f7374796c653d666c61742d737175617265)](https://instagram.com/rafaeldamasceno86)[![Source Code](https://camo.githubusercontent.com/d082022147cb68a331b75c36d2259e6c15ff9afc8c5555d4889b06a7d0a51d54/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d72616661656c646d732f72616661656c646d732d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/rafaeldms/cookie)[![PHP from Packagist](https://camo.githubusercontent.com/8b79db284aaf63f5e39288c2d2af287198877458379fc81d77bd3b008395d317/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72616661656c646d732f636f6f6b69652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rafaeldms/cookie)[![Latest Version](https://camo.githubusercontent.com/54659fe0f0557b2f1ee5815cc782dba9fe3588215da78ea64f442408686986e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f72616661656c646d732f636f6f6b69652e7376673f7374796c653d666c61742d737175617265)](https://github.com/rafaeldms/cookie/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Quality Score](https://camo.githubusercontent.com/a296e0214ab8fb9f01f5e5db80359d7d903eb183a7b39e720b81d8ffed7b47e7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f72616661656c646d732f636f6f6b69652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/rafaeldms/cookie)[![Total Downloads](https://camo.githubusercontent.com/ba3cf971506cc8f8e57dba0c20341e72cdcded1cab31108ca056a2830d8fa70c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72616661656c646d732f636f6f6b69652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rafaeldms/cookie)

###### The Cookie is a component for creating Cookies in the browser with the possibility to create, read, edit and remove cookies.

[](#the-cookie-is-a-component-for-creating-cookies-in-the-browser-with-the-possibility-to-create-read-edit-and-remove-cookies)

O Cookie é um componente para criação de Cookies nos navegadores tendo a possibilidade de criar, ler, editar e remover cookies.

### Highlights

[](#highlights)

- Simple Installation (Instalação simples)
- Easy get instance (Fácil de instanciar)
- Total controle of the cookies (Controle total dos cookies)
- Create cookies with base\_64 encryption (Crie cookies com criptografia base\_64)
- Composer ready and PSR-2 compliant (Pronto para o composer e Compatível com PSR-2)

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

[](#installation)

Cookie is available via Composer:

```
"rafaeldms/cookie": "^1.*"
```

or run

```
composer require rafaeldms/cookie
```

Documentation
-------------

[](#documentation)

###### For details on how to use the Cookie, see the sample folder with details in the component directory

[](#for-details-on-how-to-use-the-cookie-see-the-sample-folder-with-details-in-the-component-directory)

Para mais detalhes sobre como usar o Cookie, veja a pasta de exemplo com detalhes no diretório do componente

###### To start using the Cookie you can Instantiate a new Class or use it in an abstract way

[](#to-start-using-the-cookie-you-can-instantiate-a-new-class-or-use-it-in-an-abstract-way)

Para começar a usar o Cookie pode Instanciar uma nova Classe ou utilizando métodos estáticos

#### Create Cookie using static methods (Criando cookies usando o método estático)

[](#create-cookie-using-static-methods-criando-cookies-usando-o-método-estático)

```
use RafaelDms\Cookie\StaticCookie;

/**
 * Create a new cookie using the static method
 */
 StaticCookie::setCookie::set("test", "new_test", 10);
```

#### Get Cookie using static methods (Obter Cookie usando métodos estáticos)

[](#get-cookie-using-static-methods-obter-cookie-usando-métodos-estáticos)

```
 /**
 * get value the static method
 */
 echo StaticCookie::get("test");

 echo "";
```

#### Create values as array (Criando valores em array)

[](#create-values-as-array-criando-valores-em-array)

```
/**
 * Create value as array
 */
StaticCookie::set('user', ['name' => 'Rafael', 'role' => "Developer"], 10);
```

#### Get Cookie using static methods (Obter Cookie usando métodos estáticos)

[](#get-cookie-using-static-methods-obter-cookie-usando-métodos-estáticos-1)

```
/**
 * get value as array the static method
 */
echo StaticCookie::get('user')['role'];

echo "";
```

#### Delete cookie using static method (Deletar cookie usando método estático)

[](#delete-cookie-using-static-method-deletar-cookie-usando-método-estático)

```
/**
 * remove the static class
 */
StaticCookie::destroy('test');
```

#### Create if it doens't exist using method static (Criando um cookie se não existir usando método estático)

[](#create-if-it-doenst-exist-using-method-static-criando-um-cookie-se-não-existir-usando-método-estático)

```
/**
 * create if it doesn't exist the static method
 */
StaticCookie::setDoesntHave('testIfDoesntHave', true, 10000);
```

#### Create and delete if it exists the static method (Criando e deletando um cookie se existir usando método estático)

[](#create-and-delete-if-it-exists-the-static-method-criando-e-deletando-um-cookie-se-existir-usando-método-estático)

```
/**
 * create if it doesn't exist the static method
 */
StaticCookie::setDoesntHave('testIfDoesntHave', 'ok', 12500, "/admin", true);
```

#### Check if exists using a static method (Verificando se um cookie existe usando método estático)

[](#check-if-exists-using-a-static-method-verificando-se-um-cookie-existe-usando-método-estático)

```
/**
 * check if exists cookie the static class
 */
if (StaticCookie::has('testIfDoesntHave')) {
    echo "Cookie testIfDoesntHave exist";
} else {
    echo "Cookie testIfDoesntHave not exist";
}

echo "";
```

#### Check if exists by value using a static method (Verificando se um cookie existe um valor usando método estático)

[](#check-if-exists-by-value-using-a-static-method-verificando-se-um-cookie-existe-um-valor-usando-método-estático)

```
/**
 * check if exists by value
 */

if (StaticCookie::has("testIfDoesntHave", 1)) {
    echo "the value is equal to ok";
} else {
    echo "the vlaue is no equal to ok";
}
echo "";
```

Instance a new cookie object (Instanciando um novo objeto cookie)
-----------------------------------------------------------------

[](#instance-a-new-cookie-object-instanciando-um-novo-objeto-cookie)

```
use RafaelDms\Cookie\Cookie;

/**
 * Create a new cookie using construct method
 */
$cookie = new Cookie("testCookie");
```

### Set methods

[](#set-methods)

#### Set value

[](#set-value)

```
/**
 * set value a cookie using methot set
 */
$cookie->setValue("123456");
```

#### Set expiryTime

[](#set-expirytime)

```
/**
 * set expiryTime
 */
$cookie->setExpiryTime(24 * 60 * 60);
```

#### Set path

[](#set-path)

```
/**
 * set path
 */
$cookie->setPath("/admin");
```

#### Set domain

[](#set-domain)

```
/**
 * set domain
 */
$cookie->setDomain("https://www.cagep.com.br");
```

#### Set http only

[](#set-http-only)

```
/**
 * set httpOnly to false
 */
$cookie->setHttpOnly(false);
```

#### Set secure only

[](#set-secure-only)

```
/**
 * set secure only to true
 */
$cookie->setSecureOnly(true);
```

#### Save and set

[](#save-and-set)

```
/**
 * save a cookies
 */
$cookie->saveAndSet();

var_dump($cookie);
```

### Get methods

[](#get-methods)

#### Get value

[](#get-value)

```
/**
 * get value
 */
echo "Value: " . $cookie->getValue();
echo "";
```

#### Get expire time

[](#get-expire-time)

```
/**
 * get expire time
 */
echo "Expire Time: " . $cookie->getExpiryTime();
echo "";
```

#### Get path

[](#get-path)

```
/**
 * get path
 */
echo "Path: " .  $cookie->getPath();
echo "";
```

#### Get domain

[](#get-domain)

```
/**
 * get domain
 */
echo "Domain: " .  $cookie->getDomain();
echo "";
```

#### Is http only

[](#is-http-only)

```
/**
 * is http only
 */
echo "Http only: " . ($cookie->isHttpOnly() ? 'true' : 'false');
echo "";
```

#### Is secure only

[](#is-secure-only)

```
/**
 * is secure only
 */
echo "Secure only: " . ($cookie->isSecureOnly() ? 'true' : "false");
echo "";
```

#### Update value (set new value)

[](#update-value-set-new-value)

```
/**
 * update value
 */
$cookie->setValue("910111213");

var_dump($cookie);
```

#### Check if exists cookie and delete cookie

[](#check-if-exists-cookie-and-delete-cookie)

```
/*
 * check if exists cookie and delete cookie
 */
if($cookie->hasCookie()){
    var_dump($cookie);
}
```

#### Delete and unset cookie

[](#delete-and-unset-cookie)

```
/**
 * delele cookie and unset
 */
$cookie->deleteAndUnset();

var_dump($cookie);
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/rafaeldms/cookie/blob/master/CONTRIBUTING.md) for details.

Support
-------

[](#support)

###### Security: If you discover any security related issues, please email  instead of using the issue tracker.

[](#security-if-you-discover-any-security-related-issues-please-email-rafaelcagepcombr-instead-of-using-the-issue-tracker)

Se você descobrir algum problema relacionado à segurança, envie um e-mail para  em vez de usar o rastreador de problemas.

Thank you

Credits
-------

[](#credits)

- [Rafael Damasceno Ferreira](https://github.com/rafaeldms) (Developer)
- [Cagep Consultoria](https://github.com/cagep-001) (Team)
- [All Contributors](https://github.com/rafaeldms/cookie/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/rafaeldms/cookie/blob/master/LICENSE) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Recently: every ~38 days

Total

8

Last Release

1257d ago

### Community

Maintainers

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

---

Top Contributors

[![rafaeldms](https://avatars.githubusercontent.com/u/24613442?v=4)](https://github.com/rafaeldms "rafaeldms (24 commits)")

---

Tags

httphttpsxsscookiecomponentcsrfsamesiterafaeldms

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rafaeldms-cookie/health.svg)

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

###  Alternatives

[delight-im/cookie

Modern cookie management for PHP

1681.2M12](/packages/delight-im-cookie)[league/uri

URI manipulation library

1.1k206.4M277](/packages/league-uri)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

536204.9M23](/packages/league-uri-interfaces)[paragonie/cookie

Modern cookie management for PHP 7

5654.3k2](/packages/paragonie-cookie)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[mashape/unirest-php

Unirest PHP

1.3k9.7M161](/packages/mashape-unirest-php)

PHPackages © 2026

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