Signed cookies


Description


The cookie class provides a simple and consistent way to set and read signed cookies.


Methods


set(string $name, string $value [, int $ttl = 0 [, boolean $secure = false [, boolean $httpOnly = false]]])


Setting a signed cookie is done by using the set method.


// Sets signed a cookie that will expire when the browser closes.

Cookie::set('foobar', 'my value');

// Sets signed a cookie that will expire after 10 hours

Cookie::set('foobar', 'my value', (3600 * 10));

get(string $name [, string $default = null])


Reading a signed cookie is done using the get method. Unsigned cookies or cookies with an invalid signature will be ignored.


// Reads the 'foobar' cookie. If the cookie doesn't exist then $value will be set to NULL

$value = Cookie::get('foobar');

// Reads the 'foobar' cookie. If the cookie doesn't exist then $value will be set to '1234'

$value = Cookie::get('foobar', '1234');

delete(string $name)


Deleting cookies is done by using the delete method.


Cookie::delete('foobar');