Download the PHP package seba1rx/sessionadmin without Composer

On this page you can find all versions of the php package seba1rx/sessionadmin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sessionadmin

seba1rx/sessionadmin

PHP session management library with security hardening and URL authorization.


Features

Session security

URL authorization (MPA)


Quick start

SessionAdmin is abstract with no abstract methods. Extend it and define a constructor:

Then on every entry point, before any output:

Public API

Method Description
activateSession() Starts or resumes the session; runs all security checks
createUserSession(mixed $id) Marks session as authenticated, regenerates session ID
terminate() Destroys session, reinitialises as guest, redirects to index.php (MPA)
setSessionHandler(\SessionHandlerInterface $handler) Plug in a custom storage backend; call before activateSession()
setTabHandler(TabHandlerInterface $handler) Inject a tab handler (e.g. seba1rx/tabmanager); call before activateSession()

The full class is documented via docblocks — your IDE will surface every property and its purpose.

Session data written to $_SESSION['sessionadmin']

Key Present Description
appType Always 'SPA' or 'MPA' — reflects the $appIsSpa flag
isUser Always true when authenticated, false for guests
id_user After login Value passed to createUserSession()
msg Always Human-readable state label
uniqueId Always 12-char hex token, stable for the session lifetime
ipPrefix Always First N octets of the client IP (hijacking detection)
userAgent Always User-Agent string (hijacking detection)
time_atRequest Always Unix timestamp of the last request
time_sinceLastRequest Always Seconds elapsed since the previous request
allowedUrl MPA only Copy of $allowedUrls used for URL authorization
urlIsAllowedToLoad MPA only true when the current URL is in the allow-list

allowedUrl and urlIsAllowedToLoad are omitted entirely in SPA mode — they only make sense when URL authorization is active.


Custom session storage

By default the package uses PHP's native file-based session storage. Pass any SessionHandlerInterface implementation to setSessionHandler() before calling activateSession() to swap the backend:

Any PSR-compatible or custom handler works — Redis, database, encrypted file store, etc. The handler must be set before activateSession() because PHP applies the handler prior to calling session_start().


Tab isolation (optional)

Per-browser-tab session isolation is provided by the companion package seba1rx/tabmanager, which implements TabHandlerInterface.

Inject it before calling activateSession() using SessionAdminBridge — the integration class shipped with tabmanager:

SessionAdminBridge extends TabManager but does not call session_start() in its constructor — activateSession() owns the session lifecycle and configures the session name and cookie parameters before the session starts. Both packages write to distinct keys in $_SESSION (sessionadmin vs tabmanager) and do not interfere with each other.

Tab session loss (autoCleanupTabs + tabmanager:session-lost)

When $autoCleanupTabs is set, SessionAdmin prunes inactive tabs on every activateSession() call. If the browser suspends a tab (Chrome Memory Saver, OS memory pressure), the JS heartbeat pauses — and the tab may be pruned while invisible. When the user returns, tabmanager's JS client checks /tabmanager/tab-status. If the tab is no longer indexed, it fires a tabmanager:session-lost event on document and stops the heartbeat. Listen for this event to show a warning or prompt the user to reload:

The event carries event.detail.tabId with the UUID of the lost tab.


Contracts (interfaces)

The package ships two interfaces under Seba1rx\SessionAdmin\Contracts:

Interface Role Key methods
SessionInterface Implemented by SessionAdmin activateSession(), createUserSession(), terminate()
TabHandlerInterface Implemented by seba1rx/tabmanager set(), get(), isTabIndexed(), cleanupInactiveTabs(), …

TabHandlerInterface defines the full tab lifecycle contract. Any class implementing it can be injected via setTabHandler() — SessionAdmin never depends on the concrete TabManager class.

Example — mock session in tests:

Example — mock tab handler in tests:


Demos

Demo Description
demo/basic/ Minimal login/logout — the simplest possible implementation
demo/mpa/ Multi-page app with URL authorization and $allowedUrls
demo/spa/ Single-page app, SPA mode, AJAX login
demo/tabmanager/ SessionAdmin + TabManager integration — shared session, per-tab data isolation

Each demo is self-contained with its own composer.json.

Running a demo locally

  1. Install dependencies for the chosen demo:

  2. Start PHP's built-in web server from the demo directory:

  3. Open your browser and navigate to:

The built-in server serves index.php by default. Change the port if 8000 is already in use (php -S localhost:8080).


All versions of sessionadmin with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package seba1rx/sessionadmin contains the following files

Loading the files please wait ...