toolkit

Cookie

Low-level cookie handling: HttpOnly, SameSite=Lax and Path=/ always, Secure on https.

For a visitor preference the server renders (theme, density), use $app->options instead.

Cookie:: Phlat\Toolkit\Cookie 6 methods

Read 3

  • get The cookie's value, or null.
  • has Whether the request carries the cookie.
  • pick The cookie when it holds one of $values, else the first.

Write 3

  • set Sets the cookie for $ttl seconds (a year by default).
  • choose Sets $value when it is one of $values and not the first (a cookie holding the default is dropped).
  • forget Deletes the cookie.

Read

get

Cookie::get(string $name): ?string

The cookie's value, or null.

Parameters (1)
$name string

Returns ?string

phlat/src/Toolkit/Cookie.php:21

has

Cookie::has(string $name): bool

Whether the request carries the cookie.

Parameters (1)
$name string

Returns bool

phlat/src/Toolkit/Cookie.php:28
Cookie::pick(string $name, array $values): string

The cookie when it holds one of $values, else the first.

Parameters (2)
$name string
$values array

Returns string

phlat/src/Toolkit/Cookie.php:34

Write

set

Cookie::set(string $name, string $value, int $ttl = 31536000): void

Sets the cookie for $ttl seconds (a year by default).

Parameters (3)
$name string
$value string
$ttl int = 31536000
phlat/src/Toolkit/Cookie.php:43
Cookie::choose(string $name, string $value, array $values): bool

Sets $value when it is one of $values and not the first (a cookie holding the default is dropped).

False when $value is not allowed.

Parameters (3)
$name string
$value string
$values array

Returns bool

phlat/src/Toolkit/Cookie.php:56
Cookie::forget(string $name): void

Deletes the cookie.

Parameters (1)
$name string
phlat/src/Toolkit/Cookie.php:68