Mecha CMS

Cookie::set()

Set a cookie.

2.0.0 Static

Cookie::set(string $key, $value = "", int $expires = 86400);
Cookie::set(string $key, $value = "", string $expires = '1 day');
Cookie::set(string $key, $value = "", array $state = [
    'expires' => '1 day',
    'path' => '/',
    'domain' => "",
    'secure' => false,
    'httponly' => false
]);

Example:

// Quick cookie
Cookie::set('foo', 'bar', '1 day'); // Expires in a day
Cookie::set('foo', 'bar', 86400); // Expires in a day too

// Advance cookie
Cookie::set('foo', 'bar', [
    'expires' => '1 day',
    'path' => '/',
    'domain' => "",
    'secure' => false,
    'httponly' => true // Not available in `document.cookie`
]);