PHP library for handling cookies especially created for WPEngine hosted sites
This library is supported by PHP versions 5.6 or higher.
The preferred way to install this extension is through Composer.
To install WPCookie library, simply:
$ composer require WPDiggerStudio/WPCookie
You can also clone the complete repository with Git:
$ git clone https://github.com/WPDiggerStudio/WPCookie.git
Available methods in this library:
Cookie::set($key, $value, $time);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$key | Cookie name. | string | Yes | |
$value | The data to save. | string | Yes | |
$time | Expiration time in days. | string | No | 100 |
# Return (boolean)
Cookie::get($key);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$key | Cookie name. | string | No | '' |
# Return (mixed|false) → returns cookie value or false
Cookie::destroy($key);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$key | Cookie name to destroy. Not set to delete all. | string | No | '' |
# Return (boolean)
Cookie::setPrefix($prefix);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$prefix | Cookie prefix. | string | Yes |
# Return (boolean)
Cookie::getPrefix();
# Return (string) → cookie prefix
Cookie::setDomain($domain);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$domain | Cookie domain. | string | Yes |
# Return (boolean)
Cookie::getDomain();
# Return (string) → cookie domain
Cookie::setSecure($secure);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$secure | Cookie secure. | string | Yes |
# Return (boolean)
Cookie::getSecure();
# Return (string) → cookie secure
Cookie::setHttpOnly($httpOnly);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$httpOnly | Cookie httpOnly. | string | Yes |
# Return (boolean)
Cookie::getHttpOnly();
# Return (string) → cookie httpOnly
To use this class with Composer:
require __DIR__ . '/vendor/autoload.php';
use WPDiggerStudio\WPCookie\WPCookie;
Or If you installed it manually, use it:
require_once __DIR__ . '/WPCookie.php';
use WPDiggerStudio\WPCookie\WPCookie;
Example of use for this library:
Cookie::set('cookie_name', 'value', 100);
Cookie::get('cookie_name');
Cookie::get('all');
Cookie::destroy('cookie_name');
Cookie::setPrefix('prefix_');
Cookie::getPrefix();
This project is licensed under MIT license. See the LICENSE file for more info.
WPDiggerStudio, wpdigger.com
If you find it useful, let me know 😉
You can contact me through my email.