Class wwCookie

This is a support class for the wwPageResponse::AddCookie() method to allow setting cookie options more cleanly than the older way of passing a long list of parameters.

To set a cookie in this way use code like the following:

loCookie = CREATEOBJECT("wwCookie")

loCookie.CookieName = "testvalue"
loCookie.Value = "NewValue"
loCookie.Expires = DATE() + 10
loCookie.SameSite = "Strict"
loCookie.Secure = .T.
loCookie.HttpOnly = .T.

* ? loCookie.ToString()  && outputs the generated cookie string

*** Pass the cookie to set on the current request
Response.AddCookie(loCookie)

which produces a cookie string that looks like this:

testvalue=NewValue; path=/; SameSite=None; HttpOnly; Secure; Expires=Sun, 10 Nov 2019 10:00:00 GMT

Class Members

MemberDescription

Init

Initializes the cookie with optional name and value.

o.Init(lcName, lcValue)

CookieName

The name of the cookie.

Domain

Optional - the domain that the cookie applies to. This is optional and by default the current host's domain is used.

Expires

Optional - Date when the cookie expires.

By default this value is empty which means the cookie expires when the browser is shut down.

Otherwise you can make the cookie persistent, by providing an expiration date or time.

loCookie.Expires = DATE() + 10

ExtraContent

HttpOnly

Optional - If set cookie can not be accessed programmatically on the client.

Path

Optional - the site path that the Cookie is scoped to.

I recommend you do not set this value and leave it at its default to / which is the root of the site. In the past many browser versions had odd side effects not properly respecting the path and most sites simply use the root path.

SameSite

Secure

Optional - if set the cookie is sent only if the request is over HTTPS.

Note that if the request is not secure the Cookie will not set on the client and is not passed. Make sure the requests you use are HTTPS only.

Value

The actual value that is stored in the cookie as a string.

This is the value that is persisted and can be retrieved from the Cookie.

See also:

Class wwCookie

© West Wind Technologies, 1996-2024 • Updated: 06/03/20
Comment or report problem with topic