Class wwCookie

This is a support class fot the wwPageResponse::AddCookie() method to allow setting cookie options more cleanly than the older way of passing in 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 = "None"
loCookie.Secure = .T.
loCookie.HttpOnly = .T.

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

Response.AddCookie(loCookie)

which produces a cookie that looks like this:

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

Class Members

MemberDescription

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-2019 • Updated: 10/31/19
Comment or report problem with topic