Download the PHP package baraja-core/session without Composer

On this page you can find all versions of the php package baraja-core/session. 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 session

PHP Native PDO Session Storage

Simple, high-performance package for storing PHP sessions in a MySQL database using native \PDO. This package provides a robust database-backed session handler that works seamlessly with both native PHP applications and the Nette Framework.

🎯 Key Features

πŸ—οΈ Architecture Overview

The package consists of three main components that work together to provide database session storage:

🧩 Components

SessionStorage

The core component implementing PHP's \SessionHandlerInterface. It handles all session operations:

SessionExtension

A Nette Framework DI extension that provides:

SessionEntity

A Doctrine ORM entity class providing:

πŸ“¦ Installation

It's best to use Composer for installation, and you can also find the package on Packagist and GitHub.

To install, simply use the command:

You can use the package manually by creating an instance of the internal classes, or register a DIC extension to link the services directly to the Nette Framework.

Requirements

πŸ—„οΈ Database Setup

Create the database table core__session_storage (table name can be configured) or use Doctrine for automatic schema generation.

MySQL Table Schema

Note: The table can be used with Doctrine ORM or as a standalone MySQL table.

Using Doctrine Migrations

If you're using Doctrine ORM, the schema can be generated automatically from the SessionEntity class. Simply run your standard Doctrine migration commands:

βš™οΈ Configuration

Native PHP Usage

For standalone PHP applications, create a SessionStorage instance and register it as the session handler:

Warning: The session handler must be registered before calling session_start()!

Nette Framework Usage

Register the extension in your NEON configuration file:

The session storage will be configured automatically.

Manual Configuration

If you need to specify database credentials explicitly:

Automatic Doctrine DBAL Integration

When using the baraja-core/doctrine package, the extension automatically inherits database credentials from your existing DBAL connection. No additional configuration is required!

πŸ”§ Advanced Configuration

Custom Table Name

You can customize the database table name in two ways:

1. Via Constructor Parameter:

2. Via Setter Method:

3. Via NEON Configuration (Nette):

Note: The default table name is core__session_storage. While the table name can be changed at runtime, it is not recommended.

Garbage Collection

The garbage collector runs automatically with a 0.1% probability on each request. It:

πŸ”’ Security Considerations

Session Data Encoding

When session data contains characters incompatible with MySQL's UTF-8 encoding, the package automatically:

  1. Detects the encoding failure via PDO exception
  2. Re-encodes the data using Base64 with a _BASE: prefix
  3. Transparently decodes on read

This ensures binary data and special characters are safely stored without data loss.

CLI Mode Protection

Session operations are automatically skipped in CLI mode (detected by absence of $_SERVER['REMOTE_ADDR']). This prevents:

Error Handling

πŸ” How It Works

Session Lifecycle

  1. Initialization: When a request arrives, SessionStorage creates a PDO connection
  2. Reading: The read() method fetches session data by ID, creating a new record if none exists
  3. Processing: Your application uses $_SESSION as normal
  4. Writing: At request end, write() updates the session record with new data and timestamp
  5. Cleanup: GC randomly triggers to remove old sessions (0.1% probability)

Data Flow

Retry Mechanism

The loadById() method includes a retry mechanism (up to 5 attempts) for handling race conditions when creating new session records. This ensures reliability under concurrent access.

πŸ“š API Reference

SessionStorage

SessionExtension (Nette)

Configuration schema:

Option Type Required Default Description
host string No* - MySQL host
dbName string No* - Database name
username string No* - Database username
password string No* - Database password
table string No core__session_storage Table name

* Required unless Doctrine DBAL is available (credentials are then inherited automatically).

πŸ› Troubleshooting

"Session was corrupted" Error

This error appears when session data cannot be written due to encoding issues. The package attempts to re-encode using Base64, but if this also fails:

  1. Check your MySQL character set configuration
  2. Ensure the haystack column uses utf8_unicode_ci or utf8mb4_unicode_ci
  3. Clear corrupted sessions: DELETE FROM core__session_storage WHERE id = 'problematic_id'

"mb_substr" Function Not Available

The error Function "mb_substr" is not available indicates the mbstring extension is not installed. Install it:

Session Not Persisting

  1. Verify the handler is registered before session_start()
  2. Check database credentials and connectivity
  3. Ensure the session table exists with correct schema
  4. Verify you're not in CLI mode (sessions are disabled in CLI)

πŸ‘€ Author

Jan BarΓ‘Ε‘ek

πŸ“„ License

baraja-core/session is licensed under the MIT license. See the LICENSE file for more details.


All versions of session with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-pdo Version *
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 baraja-core/session contains the following files

Loading the files please wait ...