pskuza/php_session

The easy php session library.

v1.0 2018-01-29 10:04 UTC

This package is not auto-updated.

Last update: 2024-12-08 05:34:44 UTC


README

Build Status StyleCI

Install

php composer.phar require "pskuza/php_session"

Basic usage and what works

<?php

require('vendor/autoload.php');

use php_session\session;

//for memcached as cache
//check doctrine/cache on how to use the others
$memcached = new Memcached();
$memcached->setOption(Memcached::OPT_COMPRESSION, false);
$memcached->addServer('127.0.0.1', 11211);
$cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
$cacheDriver->setMemcached($memcached);

//for mysql session storage
//check pdo for other connection handlers
$db = \ParagonIE\EasyDB\Factory::create(
    'mysql:host=127.0.0.1;dbname=notdev',
    'notroot',
    'averysecurerandompassword'
);

$session = new php_session\session($db, $cacheDriver);

session_set_save_handler($session, true);

//we have a valid session
$session->start();

//write someting to it
$session->set(['somesessiondata' => 'test']);

//print it
var_dump($_SESSION);

//regenrate session id
//you should do this when the user privilege changes (not logged in => logged in or otherwise)
$session->regenerate_id();

//terminate the session (logout)
$session->logout();

//for more up to date usage see tests/SessionMysqlMemcached.php