Name: put cookie

Type: command

Syntax: put [<secure>] [<httponly>] cookie <name> [for <path>] [on <domain>] with <value> [until <expires>]

Summary: Sets a cookie in a visiting browser for a given URL.

Introduced: 4.6.4

OS: mac,windows,linux

Platforms: server

Example:
put cookie "testcookie1" with "some cookie value"

Example:
-- Expires in 1 year
put cookie "testcookie2" with "some cookie value" until (the seconds + 60 * 60 * 24 * 365)

Example:
-- Cookie available across whole website
put cookie "testcookie3" for "/" on "www.runrev.com" with "some cookie value"

Example:
-- Cookie available to specific pages
put cookie "testcookie4" for "/products/" on "www.runrev.com" with "some cookie value" until (the seconds + 60 * 60 * 24 * 365)

Example:
put secure httponly cookie "testcookie4" for "/products/" on "www.runrev.com" with "some cookie value" until (the seconds + 60 * 60 * 24 * 365)

Parameters:
secure: An optional value. If present, the browser only sends the cookie if communicating over a secure connection (https).
httponly: An optional value. If present, the cookie is only available from the browser when communicating with the server and hidden from client-side scripting (for example JavaScript).
i: 
name (String): A String containing the name by which the cookie is identified.
path (string): A string containing the path on the server at which the cookie is available. If a path is not specified, then the containing folder of the current URL is used.
domain (string): A string containing the domain at which the cookie is available. If the domain is not specified, then the domain of the current URL is used.
value (string): A string containing the contents of the cookie. This is automatically URL encoded.
expires: A number containing the time at which the cookie expires. This is expressed in seconds since the UNIX epoch (midnight, January 1, 1970 GMT). If this is not specified or empty, the cookie expires when the client browser closes.

Description:
Use the <put cookie> command to create a cookie with the given data in the visiting browser for a specific URL.

A cookie is used by a website to store state information in the user's browser, which is returned to the website on subsequent visits. Cookies are often used to store user preferences and session data. For example, you may allow a user to choose a theme through which to view your website and store this choice in a cookie to be used on subsequent visits.

When setting a cookie you can specify a path. Cookies are returned to all URLs within the specified path. For example, a cookie set on the domain "www.runrev.com" with the following path:

/products/

Is available to all pages within and under http://www.runrev.com/products/

To make the cookie available across your entire website, set the path to: "/"

>*Note:* Cookies must be set before any headers are sent.

References: $_COOKIE (keyword)
