Luminova Framework

PHP Luminova: Backend Session Security Configurations

Last updated: 2026-11-28 20:57:12

Configure session cookies, storage, lifetime, IP checks, and CSRF storage.

The Session Configuration class controls how sessions are stored, how the session cookie behaves, and which security checks apply. It is read by Luminova\Sessions\Session, the session managers, and the CSRF token manager. To get started see System Handling documentation.


Class Definition

  • Full namespace: App\Config\Session
  • File path: /app/Config/Session.php
  • This configuration derives from Luminova\Base\AbstractConfig.
  • This class is final.

Properties

cookieName

Name of the session cookie sent to the browser.

public string $cookieName = 'PHPSESSID';

When empty, PHP's current session_name() is used, falling back to PHPSESSID.


namespace

Default storage namespace for user session data.

The value is combined with the storage name to build the key where session data is stored, so changing it makes existing data unreachable.

public string $namespace = 'user_session';

Note:

  • Use a fixed, unique string (for example, an MD5 hash).
  • Do not generate it dynamically, or existing sessions will break.
  • Only letters, numbers, dots, underscores and hyphens are allowed, starting with a letter, underscore or hyphen, up to 64 characters. Anything else throws an InvalidArgumentException.

savePath

Directory where PHP stores session files on the server. It does not affect the cookie sent to the client.

public ?string $savePath = '';
ValueBehavior
'' (empty string)PHP's default session.save_path from php.ini is used.
nullSessions are saved to /writeable/sessions/ in your project root.
A pathThe directory is created with 0700 permissions if missing, and must be writable.

A RuntimeException is thrown if the directory can't be created, isn't writable,or PHP can't use it.


expiration

Session cookie lifetime in seconds. It controls how long the browser keeps the cookie.

public int $expiration = 30 * 24 * 60 * 60;
  • Default is 30 days.
  • Set to 0 to expire the cookie when the browser session ends.
  • Session::getExpiration() and the cookie manager also use this value.

gcMaxLifetime

Maximum lifetime of session data in seconds before it becomes eligible for garbage collection.

public int $gcMaxLifetime = 30 * 24 * 60 * 60;
  • Default is 30 days.
  • Applied to PHP's session.gc_maxlifetime. Values of 0 or less leave the PHP setting unchanged.
  • Keep it at least as long as expiration, otherwise data may be removed while the cookie is still valid.

sessionPath

URL path where the session cookie is available.

public string $sessionPath = '/';
  • / makes the cookie available site-wide.
  • Limit it to a subdirectory if needed.

sessionDomain

Domain for which the session cookie is valid.

public string $sessionDomain = '.localhost';
  • Set to an empty string ('') for a host-only cookie.
  • .example.com makes the cookie available on all subdomains.
  • Optionally handle domain in production using onCreate() to replaces this value with '.' . APP_HOSTNAME.

sameSite

SameSite policy for the session cookie.

public string $sameSite = 'Lax';

Options: Lax, Strict, None

  • None requires the Secure attribute, which is only set in production.
  • Any other value throws a RuntimeException when the session is configured.

cacheLimiter

Cache limiter PHP uses when starting a session. It controls the cache headers sent with responses that carry session data.

public string $cacheLimiter = 'nocache';
ValueBehavior
nocacheDisables browser and proxy caching. Default, and recommended for sensitive data.
privateAllows the user's browser to cache, but not shared caches.
private_no_expireSame as private, without an expiration header.
publicAllows both private and shared caches.
''Disables PHP's automatic cache headers.

The limiter is not applied in CLI mode.


strictSessionIp

Enable strict session IP authentication.

public bool $strictSessionIp = true;
  • When enabled, Session::login() binds the session to the client IP, or to the IP you pass to login().
  • On start(), if the IP no longer matches, the callback registered with Session::onIpChanged() runs. Without a callback, the user is logged out.
  • Passing an IP to login() while this is false throws a LogicException.

useStrictMode

Enable strict session ID validation.

public bool $useStrictMode = true;
  • When enabled, PHP rejects session IDs that don't exist in storage and issues a new one, which helps prevent session fixation.
  • Applied to PHP's session.use_strict_mode.
  • Can be changed at runtime with Session::useStrictMode() before the session starts.

See session.use_strict_mode.


encryptCookieData

Encrypt session data stored in cookies.

public bool $encryptCookieData = false;
  • Applies only when sessions are managed with Luminova\Sessions\Managers\CookieManager.
  • Uses the application's default encryption key and algorithm.
  • Encrypted cookie data is not compressed.
  • Recommended if you store sensitive data on the client.

csrfStorage

Storage used for CSRF tokens.

public string $csrfStorage = 'session';

Options:

  • session: token stored in session data.
  • cookie: token stored in a cookie.

If PHP sessions are disabled, the CSRF manager uses cookie storage regardless of this value.CSRF storage always uses SameSite=Strict and strict mode,whatever sameSite and useStrictMode are set to.


Hooks

onCreate

Runs when the configuration object is created. The default implementation sets sessionDomain to '.' . APP_HOSTNAME when PRODUCTION is enabled.

protected function onCreate(): void

These cookie attributes are fixed and have no configuration property:

  • HttpOnly is always enabled.
  • Secure is enabled only in production.

Example

namespace App\Config;

use Luminova\Base\AbstractConfig;

final class Session extends AbstractConfig
{
    public string $namespace = 'a3f1c9e2b7d84a60';
    public ?string $savePath = null;
    public int $expiration = 7 * 24 * 60 * 60;
    public int $gcMaxLifetime = 7 * 24 * 60 * 60;
    public string $sameSite = 'Strict';
    public bool $strictSessionIp = true;
}