Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bayfrontmedia/php-cookies
Helper class to easily and safely work with cookies.
https://github.com/bayfrontmedia/php-cookies
cookie cookies php
Last synced: about 6 hours ago
JSON representation
Helper class to easily and safely work with cookies.
- Host: GitHub
- URL: https://github.com/bayfrontmedia/php-cookies
- Owner: bayfrontmedia
- License: mit
- Created: 2020-07-27T18:23:46.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-26T18:02:39.000Z (almost 2 years ago)
- Last Synced: 2024-09-05T10:49:15.360Z (2 months ago)
- Topics: cookie, cookies, php
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
## PHP cookies
Helper class to easily and safely work with cookies.
- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)## License
This project is open source and available under the [MIT License](LICENSE).
## Author
- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)## Requirements
* PHP `^8.0`
## Installation
```
composer require bayfrontmedia/php-cookies
```## Usage
- [get](#get)
- [has](#has)
- [set](#set)
- [forget](#forget)
- [forgetAll](#forgetall)
### get
**Description:**
Returns value of single `$_COOKIE` array key or entire array, with optional default value.
**Parameters:**
- `$key = NULL` (string|null)
- `$default = NULL` (mixed): Default value to return if the array key is not found**Returns:**
- (mixed)
**Example:**
```
use Bayfront\Cookies\Cookie;print_r(Cookie::get());
```
### has
**Description:**
Checks if `$_COOKIE` array key exists.
**Parameters:**
- `$key` (string)
**Returns:**
- (bool)
**Example:**
```
use Bayfront\Cookies\Cookie;if (Cookie::has('cart_id')) {
// Do something
}
```
### set
**Description:**
Creates a cookie.
See: [https://www.php.net/manual/en/function.setcookie.php](https://www.php.net/manual/en/function.setcookie.php)
**Parameters:**
- `$name` (string): Cookie name
- `$value` (string): Cookie value
- `$minutes = 0` (int): Minutes from now until the cookie expires
- `$path = '/'` (string): Path on the server in which the cookie will be available
- `$domain = ''` (string): Domain/subdomain that the cookie is available to
- `$secure = true` (bool): Transmit the cookie only over a secure https connection
- `$http_only = true` (bool): Accessible only through the http protocol
- `$same_site = 'Lax'` (string): Acceptable values of `None`, `Lax` or `Strict`**Returns:**
- (bool)
**Example:**
```
use Bayfront\Cookies\Cookie;Cookie::set('cart_id', 'abc123', 60);
```
### forget
**Description:**
Removes validity of cookie.
**Parameters:**
- `$name` (string)
**Returns:**
- (void)
**Example:**
```
use Bayfront\Cookies\Cookie;Cookie::forget('cart_id');
```
### forgetAll
**Description:**
Removes the validity of all cookies.
**Parameters:**
- None
**Returns:**
- (void)
**Example:**
```
use Bayfront\Cookies\Cookie;Cookie::forgetAll();
```