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-04-29 04:07:08 UTC


README

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667

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