https://github.com/initphp/cookies
This library aims to make cookies easier to manage and a little bit more secure. It signs cookies with a (secret) salt and prevents data from being modified by the user.
https://github.com/initphp/cookies
Last synced: 10 months ago
JSON representation
This library aims to make cookies easier to manage and a little bit more secure. It signs cookies with a (secret) salt and prevents data from being modified by the user.
- Host: GitHub
- URL: https://github.com/initphp/cookies
- Owner: InitPHP
- License: mit
- Created: 2022-07-24T21:33:42.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-25T09:58:12.000Z (over 3 years ago)
- Last Synced: 2025-05-29T17:12:31.231Z (10 months ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# InitPHP Cookies Manager
This library aims to make cookies easier to manage and a little bit more secure. It signs cookies with a (secret) salt and prevents data from being modified by the user.
## Requirements
- PHP 7.2 or later
- [InitPHP ParameterBag Library](https://github.com/InitPHP/ParameterBag)
## Installation
```
composer require initphp/cookies
```
## Configuration
```php
$options = [
'ttl' => 2592000, // 30 days
'path' => '/',
'domain' => null,
'secure' => false,
'httponly' => true,
'samesite' => 'Strict'
];
```
## Usage
```php
require_once __DIR__ . "/vendor/autoload.php";
use InitPHP\Cookies\Cookie;
$cookie = new Cookie('cookie_name', 's£cr£t_s@lt', []);
$cookie->set('username', 'sdd');
```
## Methods
```php
public function has(string $key): bool;
```
***
```php
public function get(string $key, $default = null): mixed;
```
***
```php
public function pull(string $key, $default = null): mixed;
```
***
```php
public function set(string $key, string|bool|int|float $value, ?int $ttl = null): self;
```
***
```php
public function setArray(string[] $assoc, ?int $ttl = null): self;
```
***
```php
public function remove(string ...$key): bool;
```
***
```php
public function push(set $key, string|bool|int|float $value, ?int $ttl = null): string|bool|int|float;
```
***
```php
public function all(): array;
```
***
```php
public function flush(): bool;
```
***
```php
public function destroy(): bool;
```
***
## Credits
- [Muhammet ŞAFAK](https://github.com/muhammetsafak) <>
## License
Copyright © 2022 [MIT License](./LICENSE)