Skip to content

Latest commit

 

History

History
124 lines (110 loc) · 2.4 KB

README.md

File metadata and controls

124 lines (110 loc) · 2.4 KB

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