pui.setCookie( name, value, expires, ...)



This API saves a browser cookie.

Parameters:

  • name - the name of the cookie

  • value - the value to place in the cookie

  • expires - optional number of days from now that the cookie will expire in; if not specified, the cookie only lasts for the duration of a browser session and is removed when the browser is closed

  • path - optional URL path on the server in which the cookie will be available on; if set to '/', the cookie will be available within the entire domain; if set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain; the default value is the current directory that the cookie is being set in

  • domain - optional domain name that the cookie is available to; setting the domain to 'www.example.com' will make the cookie available in the www subdomain and higher subdomains. Cookies available to a lower domain, such as 'example.com' will be available to higher subdomains, such as 'www.example.com'

  • secure - optional true or false value indicating that the cookie should only be transmitted over a secure HTTPS connection. When set to true, the cookie will only be set if a secure connection exists.

  • sameSite - optional string indicating whether cookie should be sent in cross-site requests. Valid values are "None", "Strict", and "Lax". Default is to not be set, which currently behaves as if "None" were set. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies.

Example:

The following code saves the current user to a cookie that will expire in 30 days:

pui.setCookie("user", currentUser, 30);

The following code saves a cookie that will expire in 1 hour:

pui.setCookie("active", "yes", 1/24);