Kecik Cookie
Is libraries were created specifically for the Kecik Framework, this library This library is made to facilitate the use of cookies on the project we build. This library also supports data encryption so that we secure the cookie data., (*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.*@dev",
"kecik/cookie": "1.0.*@dev"
}
}
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, and then we can install this library., (*5)
How to use Cookie Library
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$cookie = new Kecik\Cookie($app);
Whereas if you want a cookie in an encrypted then we simply add the config encryption, (*6)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
//Config for encrypt cookie
$app->config->set('cookie.encrypt', TRUE);
$cookie = new Kecik\Cookie($app);
set()
This Function/Method use for create/update a cookie., (*7)
set(string $name, mixed $value)
Example:, (*8)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$cookie = new Kecik\Cookie($app);
$cookie->set('integer', 123);
$cookie->set('string', 'satu dua tiga');
$cookie->set('array', array('satu', 'dua', 'tiga'));
get()
This Function/Method use for get a value from a cookie., (*9)
get(string $name)
Example:, (*10)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$cookie = new Kecik\Cookie($app);
$cookie->set('integer', 123);
$cookie->set('string', 'satu dua tiga');
$cookie->set('array', array('satu', 'dua', 'tiga'));
echo 'cookie Integer: '.$cookie->get('integer').'<br />';
echo 'cookie String: '.$cookie->get('string').'<br />';
echo 'cookie Array: ';
print_r($cookie->get('array'));
delete()
This Function/Method use for delete a cookie., (*11)
delete(string $name)
Example:, (*12)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$cookie = new Kecik\Cookie($app);
$cookie->set('kecik_cookie', 'ini nilai cookie nya');
echo 'kecik_cookie: '.$cookie->get('kecik_cookie').'<br />';
$cookie->delete('kecik_cookie');
echo 'kecik_cookie: '.$cookie->get('kecik_cookie').'<br />';
clear()
This Function/Method use for delete all cookie are exist.
Example:, (*13)
<?php
require "vendor/autoload.php";
$app = new Kecik\Kecik();
$cookie = new Kecik\Cookie($app);
$cookie->clear();