PHPackages                             muhammetsafak/secret-cookies - 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. muhammetsafak/secret-cookies

ActiveLibrary

muhammetsafak/secret-cookies
============================

It offers a more secure cookie storage opportunity by encrypting cookies.

1.0(4y ago)03MITPHPPHP &gt;=7.4

Since May 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/muhammetsafak/SecretCookies)[ Packagist](https://packagist.org/packages/muhammetsafak/secret-cookies)[ RSS](/packages/muhammetsafak-secret-cookies/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Secret Cookies
==============

[](#secret-cookies)

It offers a more secure cookie storage opportunity by encrypting cookies.

[![Latest Stable Version](https://camo.githubusercontent.com/988dee19f84cbb7837e77b9b11eb62cc5cfca19f76c64097cb01a34ecb40d937/687474703a2f2f706f7365722e707567782e6f72672f6d7568616d6d6574736166616b2f7365637265742d636f6f6b6965732f76)](https://packagist.org/packages/muhammetsafak/secret-cookies) [![Total Downloads](https://camo.githubusercontent.com/4929ac7e9872b65821f08f2172433246c1f056a4bd3c9cfa885e31e8185d444c/687474703a2f2f706f7365722e707567782e6f72672f6d7568616d6d6574736166616b2f7365637265742d636f6f6b6965732f646f776e6c6f616473)](https://packagist.org/packages/muhammetsafak/secret-cookies) [![Latest Unstable Version](https://camo.githubusercontent.com/21438fe8dd7a95d7fa6e0a1b1a55730d8264ef3423ca07f11b18603dfcfe4743/687474703a2f2f706f7365722e707567782e6f72672f6d7568616d6d6574736166616b2f7365637265742d636f6f6b6965732f762f756e737461626c65)](https://packagist.org/packages/muhammetsafak/secret-cookies) [![License](https://camo.githubusercontent.com/baa79b743a81d72de47d99390292a3fd3e7cf3be44300827fb0e137221518543/687474703a2f2f706f7365722e707567782e6f72672f6d7568616d6d6574736166616b2f7365637265742d636f6f6b6965732f6c6963656e7365)](https://packagist.org/packages/muhammetsafak/secret-cookies) [![PHP Version Require](https://camo.githubusercontent.com/acf3747c68c5548cb74d880d83a1dff88902b2429eafdccd87ab07a2f71c866a/687474703a2f2f706f7365722e707567782e6f72672f6d7568616d6d6574736166616b2f7365637265742d636f6f6b6965732f726571756972652f706870)](https://packagist.org/packages/muhammetsafak/secret-cookies)

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- [InitPHP ParameterBag Library](https://github.com/InitPHP/ParameterBag)
- [InitPHP Encryption Library](https://github.com/InitPHP/Encryption)

***Note :*** The above libraries may have specific requirements (like **OpenSSL** and **MB\_String**).

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

[](#installation)

```
composer require muhammetsafak/secret-cookies

```

Configuration
-------------

[](#configuration)

```
$options = [
        'algo'      => 'SHA256', // String : OpenSSL Algorithm
        'cipher'    => 'AES-256-CTR', // String : OpenSSL Cipher
        'key'       => 'SecretCookie', // String : Top Secret Key
        'ttl'       => 3600, // Integer : Seconds - LifeTime
        'path'      => '/', // String
        'domain'    => null, // Null or String. If it is empty, it is not used.
        'secure'    => false, // Boolean
        'httponly'  => true, // Boolean
        'samesite'  => 'Strict', // "None", "Lax" or "Strict"
];
```

***Very Important Note :*** For security purposes, the `key` must be specified. Otherwise, using this library is just a burden for your server. Users' cookie data is encrypted and decrypted with this key.

Usage
-----

[](#usage)

```
require_once "vendor/autoload.php";
use MuhammetSafak\SecretCookies\Segment;

// See the configuration section for detailed information.
$options = [];

$cookie = new Segment('cookieName', $options);

$cookie->set('username', 'muhammetsafak')
        ->set('mail', 'info@muhammetsafak.com.tr');
```

### Performance

[](#performance)

Encryption and decryption can become a huge burden for servers in some cases. This library; it tries to avoid a repeated encryption and decryption every time.

Normally, decryption is performed with the `__construct()` method only, and encryption with the `__destruct()` method. If you still manage to escape the `__destruct()` method for some reason; you have the `save()` method that will make the changes permanent by sending them to the user's browser.

### Methods

[](#methods)

#### `has()`

[](#has)

It checks if the data is defined using the current key in the segment.

```
public function has(string $key): bool;
```

#### `get()`

[](#get)

Returns the value of the specified key. Otherwise `$default` returns the given value.

```
public function get(string $key, $default = null): mixed;
```

#### `set()`

[](#set)

Defines the value of the specified key.

```
public function set(string $key, $value): self;
```

*Note :* This method change takes effect after it but does not send it directly to the user's browser. The `save()` method should work or the object should terminate correctly for the changes to be sent to the user browser. Why and in which case the `save()` method is a must is explained in the [Performance](#performance) section.

#### `remove()`

[](#remove)

```
public function remove(string $key): self;
```

*Note :* This method change takes effect after it but does not send it directly to the user's browser. The `save()` method should work or the object should terminate correctly for the changes to be sent to the user browser. Why and in which case the `save()` method is a must is explained in the [Performance](#performance) section.

#### `save()`

[](#save)

If any, it sends the changes to the user's browser, making them permanent/valid. If the object is terminated correctly; PHP will run it automatically with the help of the `__destruct()` method.

```
public function save(): void;
```

#### `getDebug()`

[](#getdebug)

If a known error is encountered; we keep it in an array. The `getDebug()` method returns known errors, if any.

```
public function getDebug(): string[];
```

Getting Help
------------

[](#getting-help)

If you have questions, concerns, bug reports, etc, please file an issue in this repository's Issue Tracker.

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

[](#contributing)

> All contributions to this project will be published under the MIT License. By submitting a pull request or filing a bug, issue, or feature request, you are agreeing to comply with this waiver of copyright interest.

- Fork it (  )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am "Add some feature")
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) &lt;&gt;

License
-------

[](#license)

Copyright © 2022 [MIT License](./LICENSE)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

1466d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (3 commits)")

---

Tags

cookiecookiesphpphp-cookie-checkerphp-cookie-handlerphp-cookie-managementphp7

### Embed Badge

![Health badge](/badges/muhammetsafak-secret-cookies/health.svg)

```
[![Health](https://phpackages.com/badges/muhammetsafak-secret-cookies/health.svg)](https://phpackages.com/packages/muhammetsafak-secret-cookies)
```

PHPackages © 2026

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