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

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



Initializes the cookie with optional name and value.

o.Init(lcName, lcValue)


The name of the cookie.


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


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



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


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.



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.


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-2022 • Updated: 06/03/20
Comment or report problem with topic