PHP Session Manager (non-blocking, flash, segment, session encryption). Uses PHP open_ssl for optional encrypt/decryption of session data.
You can download the Latest release version as a standalone, alternatively you can use Composer
composer require ghostff/session
# Start session with default default or specified configurations.
$session = new Session();
$session->set('email', 'foo@bar.com');
echo $session->get('email');
# 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]);
# Start session with an auto generated id.
$session = new Session();
# Start session with custom ID
$session = new Session(null, bin2hex(random_bytes(32)));
$segment = $session->segment('my_segment');
echo $session->id();
# Opens, writes and closes session.
$session->commit();
$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();
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
$session->del('name');
# Removing Segment
$segment->del('name');
# Removing Flash
$session->delFlash('name');
# Removing Segment Flash
$segment->delFlash('name');
$session->getAll();
# Retrieve only in specified segment.
$session->getAll('my_segment_name');
$session->exist('name');
# Search flashes
$session->exist('name', true);
$session->clear();
$session->destroy();
$session->rotate();
# Delete the old associated session file or not
$session->rotate(true);
$session->push('age', 10)
->push('age', 20)
->push('age', 30)
->push('age', 40);
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