{cookie:name}

Description

Reads HTTP cookies sent by the visitors browser. With a cookie name, it returns that cookies value, or an empty string when the visitor has no such cookie or sent it as a list (a cookie named like name[key]; until November 2026 that stopped the page with an error). With no name, it returns every cookie as a JSON object (the raw PHP $_COOKIE array, json-encoded). The output reflects the current request and changes per visitor. A cached site page still works: every cookie the page reads by name becomes part of its page-cache key with the value it had, so the page is stored once per value of that cookie; reading all cookies (no name) switches off storing the page altogether, since the whole jar includes the session id. Since November 2026 reading the session cookie AA_Session, whenever the browser sent one, also keeps that render out of the cache, so the session id never reaches another visitor. The name is trimmed before lookup. Cookie values come straight from the browser and are not trusted input; escape them before use and never rely on them for authorization.

Parameters

name optional

Name of the cookie to read. When set, returns that cookies value (or an empty string if the visitor has no such cookie or sent it as a list). When left empty, returns all cookies encoded as a JSON object.

Examples

test[{cookie:nonexistent_demo}]
Expected[]
Actual[]
A cookie that the visitor does not have returns an empty string. The brackets here just make the empty result visible. This is the one deterministic part of cookie: any unset name yields nothing.
virtual{cookie:auth_email}
Expected(the value stored in the auth_email cookie, e.g. jane@example.org)
With a name, cookie returns that cookies value as sent by the visitors browser. The output depends on the request, so this is illustrative, not a fixed test.
virtual{cookie:}
Expected(every cookie as a JSON object, e.g. {"lang":"en","theme":"dark"})
Actual[]
With no name, cookie returns the whole $_COOKIE array json-encoded (an empty jar gives []). Useful for debugging what the browser is sending. Runtime-dependent, so illustrative.
virtual{ifset:{cookie:lang}:{cookie:lang}:en}
Expected(the lang cookie value, or en when the cookie is not set)
Actualen
The real-world pattern: read a preference cookie and supply a default when it is missing. ifset treats the empty string from an unset cookie as not set.