Kecik Session
A library created specifically for Kecik Framework, this library was made to facilitate the use session on project we build. This library also supports data encryption so that we secure the data session., (*1)
Installation
Add the following line to the file composer.json located on the project we want to build., (*2)
{
"require": {
"kecik/kecik": "1.0.2-alpha",
"kecik/session": "dev-master"
}
}
Next, run the command, (*3)
composer update
And wait until the update process is completed without error., (*4)
Note: This library requires Kecik Framework, so we need to install Kecik Framework first, then we can install this library., (*5)
How to use Session Library
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$session = new Kecik\Session($app);
Whereas if you want the session in an encrypted then we simply add the config encryption, (*6)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
//Config untuk enkripsi session
$app->config->set('session.encrypt', TRUE);
$session = new Kecik\Session($app);
id()
This Function/Method use for get session id.
Example:, (*7)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$session = new Kecik\Session($app);
echo $session->id();
newId()
This Function/Method use to make new session id.
Example:, (*8)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$session = new Kecik\Session($app);
echo 'ID SESSION: '.$session->id().'<br />';
echo 'NEW ID SESSION: '.$session->newId().'<br />';
set()
This Function/Method use for create/update a session., (*9)
set(string $name, mixed $value)
Example:, (*10)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$session = new Kecik\Session($app);
$session->set('integer', 123);
$session->set('string', 'satu dua tiga');
$session->set('array', array('satu', 'dua', 'tiga'));
get()
This Function/Method for get a value from a session., (*11)
get(string $name)
Example:, (*12)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$session = new Kecik\Session($app);
$session->set('integer', 123);
$session->set('string', 'satu dua tiga');
$session->set('array', array('satu', 'dua', 'tiga'));
echo 'session Integer: '.$session->get('integer').'<br />';
echo 'session String: '.$session->get('string').'<br />';
echo 'Session Array: ';
print_r($session->get('array'));
delete()
This Function/Method use for delete a session., (*13)
delete(string $name)
Example:, (*14)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$session = new Kecik\Session($app);
$session->set('kecik_session', 'ini nilai session nya');
echo 'kecik_session: '.$session->get('kecik_session').'<br />';
$session->delete('kecik_session');
echo 'kecik_session: '.$session->get('kecik_session').'<br />';
clear()
This Function/Method use for delete all session are exist.
Example:, (*15)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$session = new Kecik\Session($app);
$session->clear();
setExpire()
This Function/Method use for setting expiry from session., (*16)
setExpire(int $minute);
Example:, (*17)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$session = new Kecik\Session($app);
$session->setExpire(60); //session akan kadarluarsa setelah 60 menit/1 jam
getExpire()
This Function/Method use for get value expiry session.
Example:, (*18)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$session = new Kecik\Session($app);
echo $session->getExpire();