In Liten, you can set regular cookies or secure cookies which are saved in a secure location on the server.
Cookie Settings
When instantiating a Liten application, you can set the cookie lifetime and/or you can set cookie lifetime via the set cookie or set secure cookie methods.
There are several settings you can set for regular and secure cookies:
1 2 3 4 5 6 7 8 9 10 11 |
$app = new \Liten\Liten([ 'cookies.lifetime' => '1440', 'cookies.path' => '/', 'cookies.domain' => null, 'cookies.secure' => false, 'cookies.httponly' => false, // Secure Cookies 'cookies.crypt' => 'sha256', 'cookies.secret.key' => 'CHANGE_ME', 'cookies.savepath' => '/tmp/' ]); |
Note that the default path setting for secure cookies is the /tmp/ directory. If your server gets rebooted for some reason on a regular basis, you might want to change this setting. Just make sure that it is set below the root directory and is inaccessible to the public.
Regular Cookie
In order to set a regular cookie, use the set method:
1 |
$app->cookies->set($key, $value, $expires = null) |
The $expires value is the number of seconds.
To retrieve a regular cookie, use the get method:
1 |
$app->cookies->get($key) |
In order to unset a regular or secure cookie, use the remove method:
1 |
$app->cookies->remove($key) |
Secure Cookie
Secure cookies are similar to sessions in that the cookie value is a string which corresponds to a file saved on the server. Also, just like sessions, the cookie file could be deleted when the server is rebooted. However, unlike sessions, you won’t have old cookie files sitting on the server taking up space. If they have expired, they will be deleted.
A secured cookie file may look like the following:
1 |
cookies.0c967426894f0fbff47273f150a81fcd3fb649f1fae269314a06a838642c54dd |
The data in the cookie file is serialized and below is an example of the serialized data:
1 |
a:2:{s:10:"auth_token";s:1:"1";s:3:"exp";i:1429147738;} |
Last Modified:
Liten Framework › Forums › Cookies