fyre / cookie
A cookie library.
v4.0.1
2024-10-30 11:26 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^11
README
FyreCookie is a free, open-source cookie library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/cookie
In PHP:
use Fyre\Http\Cookie;
Basic Usage
$name
is a string representing the cookie name.$value
is a string representing the cookie value.$options
is an array containing cookie options.expires
is a number representing the cookie lifetime, and will default to null.domain
is a string representing the cookie domain, and will default to "".path
is a string representing the cookie path, and will default to "/".secure
is a boolean indicating whether to set a secure cookie, and will default to false.httpOnly
is a boolean indicating whether to the cookie should be HTTP only, and will default to false.sameSite
is a string representing the cookie same site, and will default to "Lax".
$cookie = new Cookie($name, $value, $options);
Methods
Get Domain
Get the cookie domain.
$domain = $cookie->getDomain();
Get Expires
Get the cookie expires timestamp.
$expires = $cookie->getExpires();
Get Header String
$headerString = $cookie->getHeaderString();
Get Name
Get the cookie name.
$name = $cookie->getName();
Get Path
Get the cookie path.
$path = $cookie->getPath();
Get Same Site
Get the cookie same site attribute.
$sameSite = $cookie->getSameSite();
Get Value
Get the cookie value.
$value = $cookie->getValue();
Is Expired
Determine whether the cookie has expired.
$expired = $cookie->isExpired();
Is Http Only
Determine whether the cookie is HTTP only.
$httpOnly = $cookie->isHttpOnly();
Is Secure
Determine whether the cookie is secure.
$secure = $cookie->isSecure();