Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ghostff/session
PHP Session Manager (non-blocking, flash, segment, session encryption)
https://github.com/ghostff/session
encryption flash memcached mysql non-blocking php7 redis session session-encryption session-management session-php sqlite
Last synced: 19 days ago
JSON representation
PHP Session Manager (non-blocking, flash, segment, session encryption)
- Host: GitHub
- URL: https://github.com/ghostff/session
- Owner: Ghostff
- License: other
- Created: 2017-02-13T22:44:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-24T14:28:04.000Z (4 months ago)
- Last Synced: 2024-10-11T18:32:46.636Z (about 1 month ago)
- Topics: encryption, flash, memcached, mysql, non-blocking, php7, redis, session, session-encryption, session-management, session-php, sqlite
- Language: PHP
- Homepage:
- Size: 70.6 MB
- Stars: 32
- Watchers: 3
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Session PHP(7.4+)
PHP Session Manager (non-blocking, flash, segment, session encryption). Uses PHP [open_ssl](http://php.net/manual/en/book.openssl.php) for **optional** encrypt/decryption of session data.### Driver Support Scope
![file](https://img.shields.io/badge/FILE-completed-brightgreen.svg?style=flat-square)
![cookie](https://img.shields.io/badge/COOKIE-completed-brightgreen.svg?style=flat-square)
![mysql](https://img.shields.io/badge/MYSQL-completed-brightgreen.svg?style=flat-square)
![sqlite](https://img.shields.io/badge/SQLITE-completed-brightgreen.svg?style=flat-square)
![memcached](https://img.shields.io/badge/MEMCACHED-completed-brightgreen.svg?style=flat-square)
![redis](https://img.shields.io/badge/REDIS-completed-brightgreen.svg?style=flat-square)
[![license](https://img.shields.io/pypi/l/Django.svg?style=flat-square)]()
[![Minimum PHP Version](https://img.shields.io/badge/PHP-%3E%3D%207.4-8892BF.svg?style=flat-square)](http://php.net/releases/7_4_0.php)# Installation
You can download the Latest [release version ](https://github.com/Ghostff/Session/releases/) as a standalone, alternatively you can use [Composer](https://getcomposer.org/)
```bash
composer require ghostff/session
```## Basic usage
```php
# Start session with default configurations.
$session = new Session();$session->set('email', '[email protected]');
echo $session->get('email');
```## Configuration Options
```php
# use custom configuration file.
Session::setConfigurationFile('path/to/my/config.php');
# overriding specific configuration settings
Session::updateConfiguration([
Session::CONFIG_DRIVER => Redis::class,
Session::CONFIG_START_OPTIONS => [
Session::CONFIG_START_OPTIONS_SAVE_PATH => __DIR__ . '/tmp'
]
]);# override a configuration for current session instance
$session = new Session([Session::CONFIG_ENCRYPT_DATA => true]);
```## Initializing Session
```php
# Start session with an auto generated id.
$session = new Session();# Start session with custom ID
$session = new Session(null, bin2hex(random_bytes(32)));
```## Using Segment *:Session*
```php
$segment = $session->segment('my_segment');
```## Retrieving Session ID *:string*
```php
echo $session->id();
```## Committing changes *:void*
```php
# Opens, writes and closes session.
$session->commit();
```## Setting Session Data *:Session*
```php
$session->set('fname', 'foo');
# Setting Segment
$segment->set('name', 'bar');# Setting Flash
$session->setFlash('name', 'foobar');
# Setting Segment Flash
$segment->setFlash('name', 'barfoo');$session->commit();
```## Retrieving Session Data *:mixed*
```php
echo $session->get('name'); # outputs foo
echo $session->getOrDefault('unset_value', 'not found'); # outputs not found
# Retrieving Segment
echo $segment->get('name'); # outputs bar
echo $segment->getOrDefault('unset_value', 'not found'); # outputs not found# Retrieving Flash
echo $session->getFlash('name'); # outputs foobar
echo $session->getFlashOrDefault('name', 'not found'); # outputs not found
# Retrieving Segment Flash
echo $segment->getFlash('name'); # outputs barfoo
echo $segment->getFlashOrDefault('name', 'not found'); # outputs not found
```## Removing Session Data *:Session*
```php
$session->del('name');
# Removing Segment
$segment->del('name');# Removing Flash
$session->delFlash('name');
# Removing Segment Flash
$segment->delFlash('name');
```## Retrieve all session or segment data *:array*
```php
$session->getAll();
# Retrieve only in specified segment.
$session->getAll('my_segment_name');
```## Check if variable exist in current session namespace *:bool*
```php
$session->exist('name');
# Search flashes
$session->exist('name', true);
```## Removing all data in current segment *:Session*
```php
$session->clear();
```## Destroying session *:void*
```php
$session->destroy();
```## Regenerate session ID *:void*
```php
$session->rotate();
# Delete the old associated session file or not
$session->rotate(true);
```## Setting Queued Session Data *:Session*
```php
$session->push('age', 10)
->push('age', 20)
->push('age', 30)
->push('age', 40);
```## Retrieving (pop/shift) Queued Session Data *:mixed*
```php
echo $session->pop('age', true); # outputs 10
echo $session->pop('age', true); # outputs 20
echo $session->pop('age'); # outputs 40
echo $session->pop('age'); # outputs 30
```