Skip to content
forked from odan/session

A middleware oriented session handler for PHP

License

Notifications You must be signed in to change notification settings

getpinga/pingsess

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pingsess

Latest Version on Packagist Software License Build Status Code Coverage Scrutinizer Code Quality Total Downloads

A middleware (PSR-15) oriented session and flash message handler for PHP, based on the wonderful odan/session. For basic documentation, check:

Common example

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

// Set a session variable
$session->set('user_id', 123);

// Get a session variable
$user_id = $session->get('user_id');

// Check if a session variable exists
if ($session->has('user_id')) {
    // ...
}

// Delete a session variable
$session->delete('user_id');

// Clear all session variables
$session->clear();

// Regenerate the session ID
$session->regenerateId();

// Destroy the session
$session->destroy();

Specific examples

$config = [
    'name' => 'app',
];

// Create a standard session handler
$session = new \Odan\Session\PhpSession($config);
use Odan\Session\MemorySession;

$session = new MemorySession();
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
use Odan\Session\FilesystemSession;

// Create a Filesystem instance
$adapter = new Local(__DIR__.'/sessions');
$filesystem = new Filesystem($adapter);

// Create a FilesystemSession instance
$session = new FilesystemSession($filesystem, [
    'name' => 'my_session',
]);
use Odan\Session\RedisSession;
use Redis;

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

$session = new RedisSession($redis, [
    'name' => 'my_app_session',
    'lifetime' => 3600,
]);
use Odan\Session\MemcachedSession;
use Memcached;

$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

$session = new MemcachedSession($memcached, [
    'name' => 'my_app_session',
    'lifetime' => 3600,
]);
use Odan\Session\PdoSession;
use PDO;

$dsn = 'mysql:host=localhost;dbname=my_database';
$username = 'my_username';
$password = 'my_password';

$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$session = new PdoSession($pdo, [
    'name' => 'my_app_session',
    'lifetime' => 3600,
    'db_table' => 'my_sessions',
]);

About

A middleware oriented session handler for PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%