PHPackages                             codezero/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. [Security](/categories/security)
4. /
5. codezero/cookie

ActiveLibrary[Security](/categories/security)

codezero/cookie
===============

Your friendly, furry cookie monster. Get and set cookies with ease.

2.0.0(6y ago)968.9k↓16.7%21MITPHPPHP &gt;=5.4.0

Since Mar 28Pushed 6y ago2 watchersCompare

[ Source](https://github.com/codezero-be/cookie)[ Packagist](https://packagist.org/packages/codezero/cookie)[ RSS](/packages/codezero-cookie/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (1)

PHP Cookies
===========

[](#php-cookies)

![GitHub release](https://camo.githubusercontent.com/b05768e8613bb0dc8c0475ee0c5fd74fd09fdffd60bc67127552ab428a05d49c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f636f64657a65726f2d62652f636f6f6b69652e737667)![License](https://camo.githubusercontent.com/7066780c00757904d972ca3d696a445716d95206b94b80eafb76b8205bac1844/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64657a65726f2f636f6f6b69652e737667)[![Build Status](https://camo.githubusercontent.com/e3e142ca3142acfb2426c557a0ce80919b84e45f3972d4847af1e63dda5e8f41/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f64657a65726f2d62652f636f6f6b69652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/codezero-be/cookie/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/649a984aaa6b780e1eed12e4f6b35f4bac372681e14e602ec684ca7213be3879/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f64657a65726f2d62652f636f6f6b69652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/codezero-be/cookie/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1c855f48c2a36e8c7a70edaa3328791be2fd24627ebf959fcfc053f3ce190afb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f64657a65726f2d62652f636f6f6b69652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/codezero-be/cookie/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/b78c149b321f9969fbf65e29e5026bf6387be12c2d616a96a844c00329225620/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64657a65726f2f636f6f6b69652e737667)](https://packagist.org/packages/codezero/cookie)

[![ko-fi](https://camo.githubusercontent.com/1fedf764fa06114b797ee53e7506df10880abed6766f854202d758df1707969d/68747470733a2f2f7777772e6b6f2d66692e636f6d2f696d672f676974687562627574746f6e5f736d2e737667)](https://ko-fi.com/R6R3UQ8V)

### Your friendly, furry cookie monster!

[](#your-friendly-furry-cookie-monster)

Get and set cookies in vanilla PHP with ease. A [Laravel](http://laravel.com/) implementation is included, but this has no real advantages if you only use Laravel.

**CAUTION!** Never store sensitive data in a cookie!

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

[](#installation)

Install this package through Composer:

```
composer require codezero/cookie
```

Vanilla PHP Implementation
--------------------------

[](#vanilla-php-implementation)

Autoload the vendor classes:

```
require_once 'vendor/autoload.php'; // Path may vary
```

And then use the `VanillaCookie` implementation:

```
$cookie = new \CodeZero\Cookie\VanillaCookie();
```

If you want your cookies to be encrypted, pass an instance of [codezero/encrypter](https://github.com/codezero-be/encrypter) to the `Cookie` class. You will also need to provide it with an encryption key that is needed to decrypt the cookie later on.

```
$key = 'my secret app key';
$encrypter = new \CodeZero\Encrypter\DefaultEncrypter($key);
$cookie = new \CodeZero\Cookie\VanillaCookie($encrypter);
```

> **TIP:** Laravel automagically encrypts cookies by default!

Laravel 5 Implementation
------------------------

[](#laravel-5-implementation)

You can "make" (or inject) a `Cookie` instance anywhere in your app:

```
$cookie = \App::make('CodeZero\Cookie\Cookie');
```

> **TIP:** Laravel's [IoC container](http://laravel.com/docs/container) will automatically provide the Laravel specific `Cookie` implementation. This will use Laravel's [`Cookie`](http://laravel.com/docs/requests) goodness behind the scenes!

Usage
-----

[](#usage)

### Get a cookie

[](#get-a-cookie)

This will return `null` if the cookie doesn't exist or is expired.

```
$cookieValue = $cookie->get('cookieName');
```

### Store a cookie for a limited time

[](#store-a-cookie-for-a-limited-time)

If you don't specify `$minutesValid`, a default of 60 minutes will be used.

```
$minutesValid = 120;
$cookie->store('cookieName', 'cookieValue', $minutesValid);
```

### Store a cookie forever

[](#store-a-cookie-forever)

5 years feels like forever... ;)

```
$cookie->forever('cookieName', 'cookieValue');
```

### Delete a cookie

[](#delete-a-cookie)

If the cookie doesn't exist, nothing will happen...

```
$cookie->delete('cookieName');
```

### Check if a cookie exists

[](#check-if-a-cookie-exists)

You can check if a cookie exists. However, keep in mind that a cookie will not be available immediately. It will be on the next page load.

```
if ($cookie->exists('cookieName')) {
    // The cookie exists!
}
```

Testing
-------

[](#testing)

```
$ composer run test
```

Security
--------

[](#security)

If you discover any security related issues, please [e-mail me](mailto:ivan@codezero.be) instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 96.7% 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 ~547 days

Total

4

Last Release

2425d ago

Major Versions

1.0.2 → 2.0.02019-09-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/2e17b7a892452367dfb0e5c55bf04844a16bb781f356f50019332d4b9a476ec6?d=identicon)[codezero](/maintainers/codezero)

---

Top Contributors

[![ivanvermeyen](https://avatars.githubusercontent.com/u/3598622?v=4)](https://github.com/ivanvermeyen "ivanvermeyen (29 commits)")[![abstractpoint](https://avatars.githubusercontent.com/u/3032975?v=4)](https://github.com/abstractpoint "abstractpoint (1 commits)")

---

Tags

cookiecookiesencryptionlaravelphpvanilla-phpphplaravelencryptcookie

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tzsk/otp

A secure, database-free One-Time Password (OTP) generator and verifier for PHP and Laravel.

241641.4k1](/packages/tzsk-otp)[hemiframe/php-aes

PHP class for encrypt and decrypt data with AES algorithm

1030.3k](/packages/hemiframe-php-aes)

PHPackages © 2026

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