This is documentation for Kohana v2.3.x.

Table of Contents
StatusDraft
TodoComments and corrections

Cookie Helper

Provides methods for working with COOKIE data.

Configuration

Default settings for cookies are specified in application/config/cookie.php. You may override these settings by passing parameters to the helper.

  1. domain: A valid domain, for which the cookie may be written. Default is '' (Use on localhost). For site-wide cookies, prefix your domain with a period .example.com
  2. path: A valid path for which the cookie may be written. Default is the root directory '/'
  3. expire: The cookie lifetime. Set the number of seconds the cookie should persist, until expired by the browser, starting from when the cookie is set. Note: Set to 0 (zero) seconds for a cookie which expires when the browser is closed. NOTE: time() will be added to this value, so be careful not to make expire too large.
  4. secure: The cookie will only be allowed over a secure transfer protocol (HTTPS). Default is FALSE.
  5. httponly: The cookie can be accessed via HTTP only, and not via client scripts. Default is FALSE. Note: Requires at least PHP version 5.2.0

Methods

set()

cookie::set() accepts multiple parameters, only the cookie name and value are required. You may pass parameters to this method as discrete values:

cookie::set($name, $value, $expire, $path, $domain, $secure, $httponly);

Or you may pass an associative array of values as a parameter:

$cookie_params = array(
               'name'   => 'Very_Important_Cookie',
               'value'  => 'Choclate Flavoured Mint Delight',
               'expire' => '86500',
               'domain' => '.example.com',
               'path'   => '/'
               );
cookie::set($cookie_params);

get()

cookie::get() accepts multiple parameters, Only the cookie name is required.

$cookie_value = cookie::get($cookie_name, $default_value = NULL, $xss_clean = FALSE);

Setting the third parameter to TRUE will filter the cookie for unsafe data.

Returns $default_value if the cookie item does not exist.

delete()

cookie::delete() accepts multiple parameters, Only the cookie name is required. This method is identical cookie::set() but sets the cookie value to '' effectively deleting it.

cookie::delete('stale_cookie');