Sessions
19 entries
$_COOKIE
Reads request cookies: under Web SAPI the Cookie request header is parsed automatically into the $_COOKIE array.
session_abort / session_reset
Two ways to drop session changes: session_reset reloads the stored values and keeps the session active; session_abort discards changes and closes the session. Together with session_write_close (commit) they form the read-modify-commit/rollback triad.
session_cache_limiter / session_cache_expire
Reads/sets the HTTP cache policy for session pages: the limiter decides which Cache-Control/Expires headers session_start sends (nocache/private/private_no_expire/public/off) and expire sets their max-age/Expires value in minutes; re-set each request before session_start.
session_create_id
Creates a collision-free session ID (charset [0-9a-zA-Z,-], optional prefix); the ID shape (length/charset) follows php.ini. Performs a collision check while a session is active — the companion tool for user-level save handlers.
session_decode / session_encode
Session-data (de)serialization: session_encode serializes $_SESSION into the internal format string (with the default handler, key names joined to serialize-encoded values by |), session_decode decodes and repopulates $_SESSION; decoding untrusted input is the same injection surface as unserialize.
session_destroy
Destroys the session data in storage (logout semantics); it does not clear the $_SESSION superglobal — clear it yourself.
session_gc
Runs one round of session garbage collection immediately (removing expired session data) and returns the number of deleted entries; a replacement for probabilistic gc_probability triggering, invoked from cron on busy sites.
session_id
Gets or sets the current session ID: calling without arguments returns the current session id, or the empty string when no session is active; passing an id replaces it (must be called before session_start()). Belongs to the session-fixation defense family together with session_regenerate_id(). The default files handler generates a 32-char lowercase-hex SID - the value is random and cannot be pre-set, so the demo asserts the format only.
session_name
Reads/writes the session cookie name (default PHPSESSID): must be set before session_start, and the return value is the OLD name - the opposite of intuition.
session_regenerate_id
Replaces the current session ID with a new one while keeping session data — the standard move in session fixation defense.
session_save_path
Reads/writes the storage directory of the built-in files handler; setting must happen before session_start(), and the setter returns the previous path (false when none was set). The storage-location switch short of session_set_save_handler.
session_set_cookie_params / session_get_cookie_params
Sets/reads the session cookie's security parameters (lifetime/path/domain/secure/httponly/samesite; 7.3+ options-array style); the effect lasts one request only and the call must run before session_start().
session_set_save_handler
Custom session storage: register a SessionHandlerInterface implementation (open/close/read/write/destroy/gc) to replace file storage - the official exit hatch for Redis/DB-backed sessions.
session_start
Starts the session (also sends the session cookie under Web SAPI); afterwards session data is read/written via $_SESSION.
session_status
Queries the three-state session machine: PHP_SESSION_DISABLED / NONE (enabled but not started) / ACTIVE (started) — the standard guard for idempotent session_start() calls.
session_unset
Empties all session variables in $_SESSION while keeping the session and its storage alive (unlike session_destroy, which removes the storage); equivalent to $_SESSION = [] and only works while a session is active.
session_write_close
Writes $_SESSION data to storage and ends the current session (releasing the write lock); later $_SESSION changes are not persisted.
setcookie
Queues a Set-Cookie response header (expiry/path/domain/HttpOnly/Secure are all header parameters); must be called before any output.
setrawcookie
Same Set-Cookie registration as setcookie, minus URL-encoding — the value goes into the header verbatim (fits base64/hashes/values already in a safe charset); values containing spaces/commas/semicolons are invalid at the HTTP layer.