Mecha CMS

Deep learning on using the API.

Class Cookie

Author: Taufik Nurrohman · 94 Views

Tweet

Persistent storage using cookies.

Table of Content

Set 

Set a cookie.

Cookie::set($key, $value = "", $config = [
    'expire' => 1,
    'path' => '/',
    'domain' => "",
    'secure' => false,
    'http_only' => false
] | $expire);

Example:

Cookie::set('my_cookie', 'the value', 1); // expired in a day

Set a cookie with advance configuration data:

Cookie::set('my_cookie', 'the value', [
    'expire' => 1,
    'path' => '/',
    'domain' => "",
    'secure' => false,
    'http_only' => true // not available in `document.cookie`
]);

Reset 

Remove a cookie.

Cookie::reset($key = null);

Example:

Cookie::reset('my_cookie');

Remove multiple cookies:

Cookie::reset(['my_cookie', 'your_cookie', 'our_cookie']);

Remove all cookies:

Cookie::reset();

Get 

Get a cookie.

Cookie::get($key = null, $fail = null);

Example:

Cookie::get('my_cookie', '#');

Get all cookies:

Cookie::get();

0 Comments

No comments yet.