PHPackages                             refkinscallv/session - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. refkinscallv/session

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

refkinscallv/session
====================

Sessions Library for PHP

1.0.5(1y ago)028MITPHP

Since Aug 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/refkinscallv/session)[ Packagist](https://packagist.org/packages/refkinscallv/session)[ RSS](/packages/refkinscallv-session/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Here's the `README.md` for the `Session` library, including installation instructions, sample `.env` file, and usage details:

---

Session Library with Timeout and Flash Data Support
===================================================

[](#session-library-with-timeout-and-flash-data-support)

The `Session` class provides advanced session management with features like automatic session timeout handling, flash data storage, and more. This library allows you to manage session values easily and securely.

---

Features
--------

[](#features)

- **Session Timeout**: Automatically expires sessions after a specified timeout period.
- **Flash Data**: Store and retrieve flash data that persists for a single session request.
- **Configurable Session Parameters**: Customize session name, timeout, path, domain, and secure flags.
- **Easy-to-Use API**: Manage session data with simple methods for setting, getting, and removing session values.

---

Installation
------------

[](#installation)

1. **Install the Package via Composer**

    To install the `refkinscallv/session` package, run the following command:

    ```
    composer require refkinscallv/session
    ```

    This command will download and install the library along with its dependencies.
2. **Include the Composer Autoloader**

    Make sure to include the Composer autoloader at the top of your PHP scripts to automatically load the classes:

    ```
    require_once 'vendor/autoload.php';
    ```
3. **Environment Configuration**

    Make sure that your environment variables are properly configured for session management. You can do this by creating a `.env` file in the root directory of your project (if not already present) with the following contents:

    **Sample `.env` File**:

    ```
    SESSION_NAME=web_session
    SESSION_TIMEOUT=1
    SESSION_PATH=/
    SESSION_SECURE=false
    ```

    This file defines:

    - `SESSION_NAME`: The name of the session.
    - `SESSION_TIMEOUT`: The session timeout duration in hours (default is 1 hour).
    - `SESSION_PATH`: The path on the server where the session is available.
    - `SESSION_SECURE`: Whether the session should be marked as secure (use HTTPS only). Set to `false` by default.
4. **Using the Library**

    After installing the package and configuring your environment, you can now begin using the `Session` class in your project.

---

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

```
use RF\Session\Session;

// Initialize the session
$session = new Session();

// Start the session
$session->start();

// Set a session value
$session->set('user', 'John Doe');

// Get a session value
echo $session->get('user'); // Outputs: John Doe

// Check if a session key exists
if ($session->has('user')) {
    echo 'User session is set.';
}

// Get multiple session values
$values = $session->some(['user', 'role']);
echo $values['user']; // Outputs: John Doe

// Set flash data
$session->setFlash('message', 'Session started successfully!');

// Get and remove flash data
echo $session->getFlash('message'); // Outputs: Session started successfully!
```

---

Configuration
-------------

[](#configuration)

### Constructor Parameters

[](#constructor-parameters)

```
public function __construct()
```

- **No parameters**: The constructor automatically reads environment variables from the server and configures the session accordingly.

### Environment Variables

[](#environment-variables)

VariableDescriptionDefault Value`SESSION_NAME`The name of the session.`web_session``SESSION_TIMEOUT`The session timeout in hours.`1` (1 hour)`SESSION_PATH`The path on the server where the session is available.`/``SESSION_SECURE`Whether the session should be secure (HTTPS only).`false`---

Methods
-------

[](#methods)

### `start()`

[](#start)

Starts the session if it hasn’t already been started.

### `set(string|array $key, mixed $value = null)`

[](#setstringarray-key-mixed-value--null)

Sets a session value or multiple values if an associative array is provided.

### `get(string $key, mixed $default = null)`

[](#getstring-key-mixed-default--null)

Retrieves a session value by key. If the key doesn’t exist, returns the provided default value.

### `some(array $keys, mixed $default = null)`

[](#somearray-keys-mixed-default--null)

Retrieves multiple session values by their keys. Returns an associative array with key-value pairs.

### `has(string $key)`

[](#hasstring-key)

Checks if a session key exists.

### `remove(string $key)`

[](#removestring-key)

Removes a session value by key.

### `setFlash(string $key, mixed $value)`

[](#setflashstring-key-mixed-value)

Sets a flash session value. Flash data will persist for one session request.

### `getFlash(string $key, mixed $default = null)`

[](#getflashstring-key-mixed-default--null)

Retrieves and removes a flash session value.

### `clear()`

[](#clear)

Clears all session values.

### `destroy()`

[](#destroy)

Destroys the session.

---

Example with Flash Data
-----------------------

[](#example-with-flash-data)

Flash data allows you to store session data that only persists for a single request. This is useful for storing messages that need to be displayed once, such as success or error messages.

```
use RF\Session\Session;

// Initialize the session
$session = new Session();

// Set flash data
$session->setFlash('success', 'Your account has been created successfully!');

// Retrieve and remove flash data
echo $session->getFlash('success'); // Outputs: Your account has been created successfully!
```

---

Notes
-----

[](#notes)

- **Session Timeout**: The session will automatically expire after the specified timeout duration, and any session data will be cleared.
- **Secure Cookies**: If you enable the `SESSION_SECURE` option, make sure to use HTTPS in your environment to ensure session data is transmitted securely.
- **Headers Sent**: Ensure that session management functions are called before any output is sent to the browser to avoid `headers already sent` errors.

---

License
-------

[](#license)

This library is released under the [MIT License](LICENSE).

###  Health Score

24

—

LowBetter than 30% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~87 days

Total

2

Last Release

636d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31750609?v=4)[Refkinscallv](/maintainers/refkinscallv)[@refkinscallv](https://github.com/refkinscallv)

---

Top Contributors

[![refkinscallv](https://avatars.githubusercontent.com/u/31750609?v=4)](https://github.com/refkinscallv "refkinscallv (3 commits)")

### Embed Badge

![Health badge](/badges/refkinscallv-session/health.svg)

```
[![Health](https://phpackages.com/badges/refkinscallv-session/health.svg)](https://phpackages.com/packages/refkinscallv-session)
```

###  Alternatives

[lavary/laravel-menu

A quick way to create menus in Laravel 5

1.2k2.2M48](/packages/lavary-laravel-menu)[webignition/internet-media-type

PHP model of an http://en.wikipedia.org/wiki/Internet\_media\_type

11156.6k14](/packages/webignition-internet-media-type)[bennettstone/magicmin

MagicMin is a PHP based javascript and stylesheet minification and merging class designed to generate minified, merged, and automatically updating files to simplify the process of minified file usage and updating when going between production and development environments.

495.9k](/packages/bennettstone-magicmin)[devletes/filament-pinnable-navigation

Pinnable navigation support for Filament 5 panels.

122.1k](/packages/devletes-filament-pinnable-navigation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
