The Cookie provides safe way to work with cookies.
composer require webiik/cookie
$cookie = new \Webiik\Cookie\Cookie();
$cookie->setCookie('foo', 'bar');
if ($cookie->isCookie('foo')) {
echo 'Cookie foo has value: ' . $cookie->getCookie('foo');
}
$cookie->delCookie('foo');
setDomain(string $domain): void
setDomain() sets the (sub)domain that the cookie is available to.
$cookie->setDomain('mydomain.tld');
setUri(string $uri): void
setUri() sets the path on the server in which the cookie will be available on.
$cookie->setUri('/');
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(bool $bool): void
setHttpOnly() indicates that the cookie should only be accessible through the HTTP protocol. The default value is FALSE.
$cookie->setHttpOnly(true);
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');
isCookie(string $name): bool
isCookie() determines if a cookie is set. Returns TRUE if cookie exists.
$cookie->isCookie('foo');
getCookie(string $name): string
getCookie() gets a cookie by $name and returns its value.
$cookie->getCookie('foo');
delCookie($name): void
delCookie() removes a cookie by $name.
$cookie->delCookie('foo');
delCookies(): void
delCookies() removes all cookies.
$cookie->delCookies();