-
Notifications
You must be signed in to change notification settings - Fork 1
Cookie
Dingo has built in functions for managing cookies. The cookie class is always avaliable to use in your applications and does not have to be loaded.
Sets a cookie and takes one argument which is an associative array.
cookie::set(array(
'name'=>'user',
'value'=>'Evan'
));
The above sets a cookie named user
with the value Evan
and it will expire when the user closes his/her browser. Here is the same example, except the cookie will expire in one month:
cookie::set(array(
'name'=>'user',
'value'=>'Evan',
'expire'=>'+1 months'
));
Here is an example using all of the settings:
cookie::set(array(
'name'=>'user',
'value'=>'Evan',
'expire'=>'+1 years +6 months +3 weeks +5 days +2 hours +1 minutes +24 seconds',
'path'=>'/',
'domain'=>'evanbot.com',
'secure'=>TRUE,
'httponly'=>TRUE
));
All of the settings - except for the expire
setting - work exactly the same as the corrisponding ones in the PHP function setcookie
.
The expire setting can be given a number of years, months, weeks, days, hours, minutes and seconds (as shown above) in any combination.
Deletes a cookie. Takes the same settings as cookie::set
minus the value
and expire
settings.
cookie::delete(array(
'name'=>'user',
'path'=>'/',
));
Optionally, you can set the first argument as just the name of the cookie. This will delete the cookie using the defualt settings.
cookie::delete('user');
This is the same as doing this:
cookie::delete(array(
'name'=>'user',
'path'=>'/',
'domain'=>FALSE,
'secure'=>FALSE,
'httponly'=>FALSE
));
Or this:
cookie::delete(array(
'name'=>'user',
'path'=>'/'
));