PHPackages                             mmdm/sim-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mmdm/sim-cookie

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

mmdm/sim-cookie
===============

A simple yet nice cookie management library

v3.0.0(4y ago)1592MITPHPPHP &gt;=7.2

Since Oct 5Pushed 4y ago1 watchersCompare

[ Source](https://github.com/mmdm95/sim-cookie)[ Packagist](https://packagist.org/packages/mmdm/sim-cookie)[ RSS](/packages/mmdm-sim-cookie/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (9)Used By (2)

Simplicity Cookie
=================

[](#simplicity-cookie)

A library for cookie management.

Features
--------

[](#features)

- Manage your cookies
- Encrypt cookie with [Crypt](https://github.com/mmdm95/sim-crypt) library(Optional)
- Manage SameSite
- Check useragent's support for SameSite

Install
-------

[](#install)

**composer**

```
composer require mmdm/sim-cookie
```

Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.

Just add line below to autoload files:

```
require_once 'path_to_library/autoloader.php';
```

and you are good to go.

How to use
----------

[](#how-to-use)

```
// to instantiate a cookie object
$cookie = new Cookie();

// then use cookie methods like
$cookie->get($cookie_name);
```

Use with Crypt library
----------------------

[](#use-with-crypt-library)

If you need more security on cookies, use [Crypt](https://github.com/mmdm95/sim-crypt) library.

```
// send crypt instance through cookie
// constructure (dependency injection)
$cookie = new Cookie($crypt);
// now your cookies are safe
```

If you don't need some of your cookies to be secure, pass false as last parameter of setValue of `ISetCookie` method.

Available methods
-----------------

[](#available-methods)

### Cookie

[](#cookie)

#### `parse(string $cookie_string, bool $decode = false, bool $encrypt = true): ?ISetCookie`

[](#parsestring-cookie_string-bool-decode--false-bool-encrypt--true-isetcookie)

Send a cookie string to parse it into `SetCookie` object or null if it can't parse.

**Note:**

To decode value of parsed string, pass true to `$decode` parameter.

To encrypt parsed value, pass true as `$encrypt` parameter.

ParameterTypeDefault$cookie\_stringISetCookie$decodeboolfalse$encryptbooltrue#### `set(string $name): ISetCookie`

[](#setstring-name-isetcookie)

Create new cookie object and can modify all inputs after `set`method.

Please refer to [SetCookie Available Methods](#setcookie-available-methods) for more information.

#### `get(?string $name = null, $prefer = null)`

[](#getstring-name--null-prefer--null)

Get cookie's value or `$prefer` if not defined.

**Note**

To get all cookies, do not send any parameter.

#### `getAsString(?string $name = null, bool $decode = true, bool $decrypt = false): string`

[](#getasstringstring-name--null-bool-decode--true-bool-decrypt--false-string)

Get string for a cookie.

**Note**

To get all cookies as string, send null as `$name`

#### `remove(string $name): ICookie`

[](#removestring-name-icookie)

Remove a cookie(event from `$_COOKIE` variable).

#### `has(string $name): bool`

[](#hasstring-name-bool)

Check if there is cookie with specific name.

#### `getCookieValueFromString(string $str)`

[](#getcookievaluefromstringstring-str)

Get(decrypted) value.

**Note**

It is useful when there is a cookie value is inside a header and want get actual value and check it.

```
$value = $cookie->getCookieValueFromString($the_cookie_value_that_is_encrypted_or_raw);
```

---

### SetCookie Available Methods

[](#setcookie-available-methods)

#### `getName(): ?string`

[](#getname-string)

Get cookie name.

#### `setValue(?string $value, bool $encrypt = true): ISetCookie`

[](#setvaluestring-value-bool-encrypt--true-isetcookie)

Set value of cookie.

**Note**

To encrypt value pass *true* as second parameter.

#### `getValue(): string`

[](#getvalue-string)

Get cookie value.

#### `setExpiration($expire): ISetCookie`

[](#setexpirationexpire-isetcookie)

Set expiration to cookie.

#### `getExpiration(): int`

[](#getexpiration-int)

Get expiration of cookie.

#### `setPath(?string $path): ISetCookie`

[](#setpathstring-path-isetcookie)

Set cookie path.

#### `getPath(): ?string`

[](#getpath-string)

Get cookie path.

#### `setDomain(?string $domain): ISetCookie`

[](#setdomainstring-domain-isetcookie)

Set domain of cookie.

#### `getDomain(): ?string`

[](#getdomain-string)

Get cookie domain.

#### `setSecure(?bool $answer): ISetCookie`

[](#setsecurebool-answer-isetcookie)

Set secure string to cookie.

#### `isSecure(): ?bool`

[](#issecure-bool)

Check if secure string set or not.

#### `setHttpOnly(?bool $answer): ISetCookie`

[](#sethttponlybool-answer-isetcookie)

Set httponly string to cookie.

#### `isHttpOnly(): ?bool`

[](#ishttponly-bool)

Check if httponly set or not.

#### `setSameSite(?string $same_site): ISetCookie`

[](#setsamesitestring-same_site-isetcookie)

Set same site for modern browsers.

**Note**

Acceptable values are:

- ICookie::SAME\_SITE\_NONE - is `None` string
- ICookie::SAME\_SITE\_LAX - is `Lax` string
- ICookie::SAME\_SITE\_STRICT - is `Strict` string

#### `getSameSite(): ?string`

[](#getsamesite-string)

Get samesite if set before or `null`.

#### `setExtra(string $extra): ISetCookie`

[](#setextrastring-extra-isetcookie)

Set extra string for cookie (if needed and supported).

#### `getExtra(): string`

[](#getextra-string)

Get extra cookie string

#### `setUseragent(?string $useragent = null): ISetCookie`

[](#setuseragentstring-useragent--null-isetcookie)

Set useragent for check against to see if it support samesite or not.

**Note**

By default it'll get browser from `$_SERVER`.

#### `getUseragent(): ?string`

[](#getuseragent-string)

Get useragent.

**Note**

This method will return the useragent you set not useragent from `$_SERVER` variable.

#### `toString(bool $decode = true, bool $decrypt = false): string`

[](#tostringbool-decode--true-bool-decrypt--false-string)

Get cookie header of this cookie as string

Example of output:

```
"Set-Cookie: tmp-cookie=A simple cookie; expires=Sat, 03-Apr-2021 10:45:55 GMT; Max-Age=60"
"Set-Cookie: tmp-cookie=A simple cookie number 2; expires=Sat, 03-Apr-2021 10:45:55 GMT; Max-Age=60; secure; SameSite=None"
```

#### `save(bool $encode = true): bool`

[](#savebool-encode--true-bool)

Save configured cookie. `$encode` will encode `value`.

**Note**

You **MUST** call this method to save cookie otherwise you missed your cookie.

Dependencies
============

[](#dependencies)

There is just one dependency and it is [Crypt](https://github.com/mmdm95/sim-crypt) library. With this feature, if any cookie hijacking happens, they can't see actual data because it is encrypted.

License
=======

[](#license)

Under MIT license.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

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

Recently: every ~74 days

Total

8

Last Release

1709d ago

Major Versions

v1.2.1 → v2.0.22021-06-14

v2.0.2 → v3.0.02021-09-12

### Community

Maintainers

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

---

Top Contributors

[![mmdm95](https://avatars.githubusercontent.com/u/26489185?v=4)](https://github.com/mmdm95 "mmdm95 (37 commits)")

### Embed Badge

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

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

PHPackages © 2026

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