Scroll to navigation

GOLF(2gg) Development GOLF(2gg)

NAME

set-cookie - (cookies)

PURPOSE

Set cookie.

SYNTAX

set-cookie ( <cookie name>=<cookie value> \

[ expires <expiration> ] \
[ path <path> ] \
[ same-site "Lax"|"Strict"|"None" ] \
[ no-http-only [ <no-http-only> ] ] \
[ secure [ <secure> ] ] ) ,...

DESCRIPTION

To set a cookie named by string <cookie name> to string value <cookie value>, use set-cookie statement. A cookie must be set prior to outputting any actual response (such as with output-statement or print-out for example), or the program will error out and stop.

Cookie's <expiration> date (as a string, see get-time) is given with "expires" clause. The default is session cookie meaning the cookie expires when client session closes.

Cookie's <path> is specified with "path" clause. The default is the URL path of the request URL.

Whether a cookie applies to the same site is given with "same-site" clause along with possible values of "Lax", "Strict" or "None".

By default a cookie is not accessible to client scripting (i.e. "HttpOnly") -you can change this with "no-http-only" clause. That will be the case if "no-http-only" clause is used without bool expression <no-http-only>, or if <no-http-only> evaluates to true.

Use "secure" if a secure connection (https) is used, in order to specify this cookie is available only with a secure connection. That will be the case if "secure" is used without bool expression <secure>, or if <secure> evaluates to true.

Cookies are commonly used for session maintenance, tracking and other purposes. Use get-cookie and delete-cookie together with set-cookie to manage cookies.

You can set multiple cookies separated by a comma:

get-time to tm year 1
set-cookie "mycookie1"="4900" expires tm path "/", "mycookie2"="900" expires tm  path "/my-app" same-site "Strict"

EXAMPLES

To set a cookie named "my_cookie_name" to value "XYZ", that will go with the reply and expire in 1 year and 2 months from now, use:

get-time to mytime year 1 month 2
set-string my_cookie_value="XYZ"
set-cookie "my_cookie_name"=my_cookie_value expires mytime path "/" same-site "Lax"

A cookie that can be used by JavaScript (meaning we use no-http-only clause):

set-cookie "my_cookie_name"=my_cookie_value no-http-only

SEE ALSO


Cookies

delete-cookie get-cookie set-cookie See all documentation

$VERSION $DATE