W3cubDocs

/CakePHP 4.1

Interface CookieInterface

Cookie Interface

Namespace: Cake\Http\Cookie

Constants summary

  • string
    EXPIRES_FORMAT
    'D, d-M-Y H:i:s T'
  • string
    SAMESITE_LAX
    'Lax'
  • string
    SAMESITE_NONE
    'None'
  • string
    SAMESITE_STRICT
    'Strict'
  • string[]
    SAMESITE_VALUES
    [self::SAMESITE_LAX, self::SAMESITE_STRICT, self::SAMESITE_NONE]

Method Summary

Method Detail

getDomain() public

getDomain()

Get the domain attribute.

Returns

string

getExpiresTimestamp() public

getExpiresTimestamp()

Get the timestamp from the expiration time

Returns

int|null

The expiry time as an integer.

getExpiry() public

getExpiry()

Get the current expiry time

Returns

\DateTime|\DateTimeImmutable|null

Timestamp of expiry or null

getFormattedExpires() public

getFormattedExpires()

Builds the expiration value part of the header string

Returns

string

getId() public

getId()

Get the id for a cookie

Cookies are unique across name, domain, path tuples.

Returns

string

getName() public

getName()

Gets the cookie name

Returns

string

getOptions() public

getOptions()

Get cookie options

Returns

array

getPath() public

getPath()

Get the path attribute.

Returns

string

getSameSite() public

getSameSite()

Get the SameSite attribute.

Returns

string|null

getScalarValue() public

getScalarValue()

Gets the cookie value as scalar.

This will collapse any complex data in the cookie with json_encode()

Returns

mixed

getValue() public

getValue()

Gets the cookie value

Returns

string|array

isExpired() public

isExpired(mixed $time)

Check if a cookie is expired when compared to $time

Cookies without an expiration date always return false.

Parameters

\DateTime|\DateTimeImmutable $time optional

The time to test against. Defaults to 'now' in UTC.

Returns

bool

isHttpOnly() public

isHttpOnly()

Check if the cookie is HTTP only

Returns

bool

isSecure() public

isSecure()

Check if the cookie is secure

Returns

bool

toArray() public

toArray()

Get cookie data as array.

Returns

array

With keys name, value, expires etc. options.

toHeaderValue() public

toHeaderValue()

Returns the cookie as header value

Returns

string

withDomain() public

withDomain(string $domain)

Create a cookie with an updated domain

Parameters

string $domain

Domain to set

Returns

static

withExpired() public

withExpired()

Create a new cookie that will expire/delete the cookie from the browser.

This is done by setting the expiration time to 1 year ago

Returns

static

withExpiry() public

withExpiry(mixed $dateTime)

Create a cookie with an updated expiration date

Parameters

\DateTime|\DateTimeImmutable $dateTime

Date time object

Returns

static

withHttpOnly() public

withHttpOnly(bool $httpOnly)

Create a cookie with HTTP Only updated

Parameters

bool $httpOnly

HTTP Only

Returns

static

withName() public

withName(string $name)

Sets the cookie name

Parameters

string $name

Name of the cookie

Returns

static

withNeverExpire() public

withNeverExpire()

Create a new cookie that will virtually never expire.

Returns

static

withPath() public

withPath(string $path)

Create a new cookie with an updated path

Parameters

string $path

Sets the path

Returns

static

withSameSite() public

withSameSite(?string $sameSite)

Create a cookie with an updated SameSite option.

Parameters

string|null $sameSite

Value for to set for Samesite option. One of CookieInterface::SAMESITE_* constants.

Returns

static

withSecure() public

withSecure(bool $secure)

Create a cookie with Secure updated

Parameters

bool $secure

Secure attribute value

Returns

static

withValue() public

withValue(mixed $value)

Create a cookie with an updated value.

Parameters

string|array $value

Value of the cookie to set

Returns

static

© 2005–present 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/4.1/interface-Cake.Http.Cookie.CookieInterface.html