Cookie object to build a cookie and turn it into a header value
An HTTP cookie (also called web cookie, Internet cookie, browser cookie or simply cookie) is a small piece of data sent from a website and stored on the user's computer by the user's web browser while the user is browsing.
Cookies were designed to be a reliable mechanism for websites to remember stateful information (such as items added in the shopping cart in an online store) or to record the user's browsing activity (including clicking particular buttons, logging in, or recording which pages were visited in the past). They can also be used to remember arbitrary pieces of information that the user previously entered into form fields such as names, and preferences.
Cookie objects are immutable, and you must re-assign variables when modifying cookie objects:
$cookie = $cookie->withValue('0');
$domain
protected string
$expiresAt
protected DateTime|DateTimeImmutable|null
$httpOnly
protected boolean
$isExpanded
protected boolean
$name
protected string
$path
protected string
$secure
protected boolean
$value
protected string|array
Explode method to return array from string set in CookieComponent::_flatten() Maintains reading backwards compatibility with 1.x CookieComponent::_flatten().
__construct( string $name , string|array $value '' , DateTime|DateTimeImmutable|null $expiresAt null , string $path '' , string $domain '' , boolean $secure false , boolean $httpOnly false )
Constructor
The constructors args are similar to the native PHP setcookie()
method. The only difference is the 3rd argument which excepts null or an DateTime or DateTimeImmutable object instead an integer.
$name
$value
optional '' $expiresAt
optional null $path
optional '' $domain
optional '' $secure
optional false $httpOnly
optional false _expand( string $string )
Explode method to return array from string set in CookieComponent::_flatten() Maintains reading backwards compatibility with 1.x CookieComponent::_flatten().
$string
_flatten( array $array )
Implode method to keep keys are multidimensional arrays
$array
_setValue( mixed $value )
Setter for the value attribute.
$value
check( string $path )
Checks if a value exists in the cookie data.
This method will expand serialized complex data, on first use.
$path
getDomain( )
Get the domain attribute.
Cake\Http\Cookie\CookieInterface::getDomain()
getExpiresTimestamp( )
Get the timestamp from the expiration time
Cake\Http\Cookie\CookieInterface::getExpiresTimestamp()
getExpiry( )
Get the current expiry time
Cake\Http\Cookie\CookieInterface::getExpiry()
getFormattedExpires( )
Builds the expiration value part of the header string
Cake\Http\Cookie\CookieInterface::getFormattedExpires()
getId( )
Get the id for a cookie
Cake\Http\Cookie\CookieInterface::getId()
getName( )
Gets the cookie name
Cake\Http\Cookie\CookieInterface::getName()
getPath( )
Get the path attribute.
Cake\Http\Cookie\CookieInterface::getPath()
getStringValue( )
Gets the cookie value as a string.
Cake\Http\Cookie\CookieInterface::getStringValue()
getValue( )
Gets the cookie value
Cake\Http\Cookie\CookieInterface::getValue()
isExpired( DateTime|DateTimeImmutable $time null )
Check if a cookie is expired when compared to $time
$time
optional null Cake\Http\Cookie\CookieInterface::isExpired()
isHttpOnly( )
Check if the cookie is HTTP only
Cake\Http\Cookie\CookieInterface::isHttpOnly()
isSecure( )
Check if the cookie is secure
Cake\Http\Cookie\CookieInterface::isSecure()
read( string $path null )
Read data from the cookie
This method will expand serialized complex data, on first use.
$path
optional null toHeaderValue( )
Returns a header value as string
Cake\Http\Cookie\CookieInterface::toHeaderValue()
validateBool( boolean $value )
Validate that an argument is a boolean
$value
validateName( string $name )
Validates the cookie name
$name
validateString( string $value )
Validate that an argument is a string
$value
withAddedValue( string $path , mixed $value )
Create a new cookie with updated data.
$path
$value
Cake\Http\Cookie\Cookie
withDomain( string $domain )
Create a cookie with an updated domain
$domain
Cake\Http\Cookie\Cookie
Cake\Http\Cookie\CookieInterface::withDomain()
withExpired( )
Create a new cookie that will expire/delete the cookie from the browser.
Cake\Http\Cookie\Cookie
Cake\Http\Cookie\CookieInterface::withExpired()
withExpiry( DateTime|DateTimeImmutable $dateTime )
Create a cookie with an updated expiration date
$dateTime
Cake\Http\Cookie\Cookie
Cake\Http\Cookie\CookieInterface::withExpiry()
withHttpOnly( boolean $httpOnly )
Create a cookie with HTTP Only updated
$httpOnly
Cake\Http\Cookie\Cookie
Cake\Http\Cookie\CookieInterface::withHttpOnly()
withName( string $name )
Sets the cookie name
$name
Cake\Http\Cookie\Cookie
Cake\Http\Cookie\CookieInterface::withName()
withNeverExpire( )
Create a new cookie that will virtually never expire.
Cake\Http\Cookie\Cookie
Cake\Http\Cookie\CookieInterface::withNeverExpire()
withPath( string $path )
Create a new cookie with an updated path
$path
Cake\Http\Cookie\Cookie
Cake\Http\Cookie\CookieInterface::withPath()
withSecure( boolean $secure )
Create a cookie with Secure updated
$secure
Cake\Http\Cookie\Cookie
Cake\Http\Cookie\CookieInterface::withSecure()
withValue( string|array $value )
Create a cookie with an updated value.
$value
Cake\Http\Cookie\Cookie
Cake\Http\Cookie\CookieInterface::withValue()
withoutAddedValue( string $path )
Create a new cookie without a specific path
$path
Cake\Http\Cookie\Cookie
protected boolean
Whether or not a JSON value has been expanded into an array.
false
© 2005–2018 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.5/class-Cake.Http.Cookie.Cookie.html