webiik/cookie

The Cookie provides safe way to work with cookies.

1.0 2019-02-28 21:18 UTC

This package is auto-updated.

Last update: 2024-10-29 05:47:34 UTC


README

Cookie

The Cookie provides safe way to work with cookies.

Installation

composer require webiik/cookie

Example

$cookie = new \Webiik\Cookie\Cookie();
$cookie->setCookie('foo', 'bar');
if ($cookie->isCookie('foo')) {
    echo 'Cookie foo has value: ' . $cookie->getCookie('foo');
}
$cookie->delCookie('foo');

Configuration

setDomain

setDomain(string $domain): void

setDomain() sets the (sub)domain that the cookie is available to.

$cookie->setDomain('mydomain.tld');

setUri

setUri(string $uri): void

setUri() sets the path on the server in which the cookie will be available on.

$cookie->setUri('/');

setSecure

setSecure(bool $bool): void

setSecure() indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. The default value is FALSE.

$cookie->setSecure(true);

setHttpOnly

setHttpOnly(bool $bool): void

setHttpOnly() indicates that the cookie should only be accessible through the HTTP protocol. The default value is FALSE.

$cookie->setHttpOnly(true);

Adding

setCookie

setCookie(string $name, string $value = '', int $expire = 0, string $uri = '', string $domain = '', bool $secure = false, bool $httponly = false): bool

setCookie() sets a cookie to be sent along with the rest of the HTTP headers.

$cookie->setCookie('foo', 'bar');

Check

isCookie

isCookie(string $name): bool

isCookie() determines if a cookie is set. Returns TRUE if cookie exists.

$cookie->isCookie('foo');

Getting

getCookie

getCookie(string $name): string

getCookie() gets a cookie by $name and returns its value.

$cookie->getCookie('foo');

Deletion

delCookie

delCookie($name): void

delCookie() removes a cookie by $name.

$cookie->delCookie('foo');

delCookies

delCookies(): void

delCookies() removes all cookies.

$cookie->delCookies();

Resources