[session]
session
Where a session's record lives, how long an untouched one survives, and what the cookie carrying its identifier is called.
A session must be the same session whichever server process or host answers the next request. So a session can be kept in only two places: the shared store, or a database table. Core\Cache::memory() is kept inside one server process, so backend = "memory" is not allowed. A server with that line in nvs.toml does not start. A session kept in one process is lost when another process answers or the server restarts. The user is logged out, or their basket is empty.
In plain words: a session is not a cache, and this block only offers stores that can prove it.
The cookie's name is here and its attributes are not. Every cookie this server writes is already secure, HTTP-only and same-site, so a second place to spell those would only ever be a way to weaken them. The whole block is the operator's and is bound when the process starts.
The example prints where sessions live in this deployment, what the cookie is called, and is turned away moving either.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
Where a session is kept
<?nvs// `[session]` sets where sessions are stored, how long values are kept,// and the name of the session cookie://// [session]// backend = "shared" # or "db"; no other value is allowed// short_lived = "2h"// long_lived = "180d"// cookie = "nvs_session"
// This file does not write `[session]`. So the last three keys have their defaults.echo 'records live in: ', Core\Config::get('session.backend') ?? '(nothing written — a program that wants a session says so)', "\n";echo 'short-lived for: ', Core\Config::get('session.short_lived') ?? '(no value)', "\n";echo 'long-lived for: ', Core\Config::get('session.long_lived') ?? '(no value)', "\n";echo 'cookie name: ', Core\Config::get('session.cookie') ?? '(no value)', "\n";
// A program cannot change any setting in `[session]`. A name written directly in the// call does not compile. Each name below is in a variable, so the call runs and returns `false`.
// There are only two stores. The next request may run in another server process,// so `memory` is not allowed and this call returns `false`.string $backend = 'session.backend';echo 'keep mine in memory: ', Core\Config::set($backend, 'memory') ? 'accepted' : 'not allowed', "\n";
// A program cannot change how long a session value is kept. A longer time makes a// stolen session cookie useful for longer.string $shortLived = 'session.short_lived';echo 'keep mine for a year: ', Core\Config::set($shortLived, '8760h') ? 'accepted' : 'not allowed', "\n";
// A program cannot rename the cookie either. Every cookie this server writes is// secure, HTTP-only and same-site, and no setting changes that.string $cookie = 'session.cookie';echo 'rename the cookie: ', Core\Config::set($cookie, 'sid') ? 'accepted' : 'not allowed', "\n";records live in: (nothing written — a program that wants a session says so)short-lived for: 2hlong-lived for: 180dcookie name: nvsidkeep mine in memory: not allowedkeep mine for a year: not allowedrename the cookie: not allowed