Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

21 Commits

Repository files navigation

WPCookie

PHP library for handling cookies especially created for WPEngine hosted sites



Requirements

This library is supported by PHP versions 5.6 or higher.

Installation

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

Available methods in this library:

- Set cookie:

Cookie::set($key, $value, $time);
AttributeDescriptionTypeRequiredDefault
$keyCookie name.stringYes
$valueThe data to save.stringYes
$timeExpiration time in days.stringNo100

# Return (boolean)

- Get item from cookie:

Cookie::get($key);
AttributeDescriptionTypeRequiredDefault
$keyCookie name.stringNo''

# Return (mixed|false) → returns cookie value or false

- Extract item from cookie and delete cookie:

Cookie::destroy($key);
AttributeDescriptionTypeRequiredDefault
$keyCookie name to destroy. Not set to delete all.stringNo''

# Return (boolean)

- Set cookie prefix:

Cookie::setPrefix($prefix);
AttributeDescriptionTypeRequiredDefault
$prefixCookie prefix.stringYes

# Return (boolean)

- Get cookie prefix:

Cookie::getPrefix();

# Return (string) → cookie prefix


- Set cookie domain:

Cookie::setDomain($domain);
AttributeDescriptionTypeRequiredDefault
$domainCookie domain.stringYes

# Return (boolean)

- Get cookie domain:

Cookie::getDomain();

# Return (string) → cookie domain

- Set cookie secure:

Cookie::setSecure($secure);
AttributeDescriptionTypeRequiredDefault
$secureCookie secure.stringYes

# Return (boolean)

- Get cookie secure:

Cookie::getSecure();

# Return (string) → cookie secure

- Set cookie httpOnly:

Cookie::setHttpOnly($httpOnly);
AttributeDescriptionTypeRequiredDefault
$httpOnlyCookie httpOnly.stringYes

# Return (boolean)

- Get cookie httpOnly:

Cookie::getHttpOnly();

# Return (string) → cookie httpOnly

Quick Start

To use this class with Composer:

require__DIR__ . '/vendor/autoload.php';
useWPDiggerStudio\WPCookie\WPCookie;

Or If you installed it manually, use it:

require_once__DIR__ . '/WPCookie.php';
useWPDiggerStudio\WPCookie\WPCookie;

Usage

Example of use for this library:

- Set cookie:

Cookie::set('cookie_name', 'value', 100);

- Get cookie:

Cookie::get('cookie_name');

- Get all cookies:

Cookie::get('all');

- Destroy one cookie:

Cookie::destroy('cookie_name');

- Set cookie prefix:

Cookie::setPrefix('prefix_');

- Get cookie prefix:

Cookie::getPrefix();

License

This project is licensed under MIT license. See the LICENSE file for more info.

Copyright

WPDiggerStudio, wpdigger.com

If you find it useful, let me know 😉

You can contact me through my email.

About

PHP library for handling cookies especially created for WPEngine hosted sites

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages