Creating Cookies
The documentation in PeopleBooks regarding the Cookie
class is a little unclear. Here's a simple example of the PeopleCode you could use to create your own cookie and how to set properties in the cookie class:
Local object &Response = %Response;
Local object &YourCookie;
&YourCookie = &Response.CreateCookie("YourCookieName");
&YourCookie.Domain = %Request.AuthTokenDomain;
&YourCookie.MaxAge = -1; /* Makes this a session cookie (default) */
&YourCookie.Path = "/";
&YourCookie.Secure = True; /* Set to true if using https (will still work with http) */
&YourCookie.Value = "Set the cookie value here. Encrypt sensitive information.";
If you don't see your cookie make sure you have set your domain correctly (with leading full stop) to match your environment. If this is incorrect, the cookie will not be created.
If you make the MaxAge
greater than 0, that defines the lifetime of the cookie in seconds. A cookie with a MaxAge
of 0 is deleted immediately (not sure what you would use that for?).
No Comments