# Class Cookie

- [TopLevel.Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - [dw.web.Cookie](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md)

Represents an HTTP cookie used for storing information on a client browser. Cookies are passed along in the HTTP
request and can be retrieved by calling dw\.system.Request.getHttpCookies().

Cookies must comply with RFC6265. We recommend you use only printable ASCII characters without separators, such as a
comma or equal sign. If JSON is used as a cookie value, it must be encoded.

**Note:** this class allows access to sensitive security-related data. Pay special attention to PCI DSS v3.
requirements 2, 4, and 12.

See [Request.getHttpCookies()](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.system.Request.md#gethttpcookies).

## Constant Summary

| Constant                                                                                                                       | Description                                  |
| ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------- |
| [EMPTYNAME](#emptyname): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) = "dw_emptyname__" | Default name for cookies with empty strings. |

## Property Summary

| Property                                                                                                        | Description                                                                                 |
| --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| ~~[comment](#comment): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)~~     | Returns the comment that was previously set for this cookie, or null if no comment was set. |
| [domain](#domain): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)           | Returns the domain associated with the cookie.                                              |
| [httpOnly](#httponly): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)     | Identifies if the cookie is http-only.                                                      |
| [maxAge](#maxage): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)           | Returns the maximum age of the cookie, specified in seconds.                                |
| [name](#name): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)` | Returns the cookie's name.                                                                  |
| [path](#path): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)               | Returns the path for the cookie.                                                            |
| [secure](#secure): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)         | Identifies if the cookie is secure.                                                         |
| [value](#value): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)             | Returns the cookie's value.                                                                 |
| ~~[version](#version): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)~~     | Returns the version that was previously set for this cookie.                                |

## Constructor Summary

| Constructor                                                                                                                                                                                            | Description                                                 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------- |
| [Cookie](#cookiestring-string)([String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md), [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)) | Constructs a new cookie using the specified name and value. |

## Method Summary

| Method                                                                                                                                                                                         | Description                                                                                 |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| ~~[getComment](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#getcomment)()~~                                                                                          | Returns the comment that was previously set for this cookie, or null if no comment was set. |
| [getDomain](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#getdomain)()                                                                                                | Returns the domain associated with the cookie.                                              |
| [getMaxAge](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#getmaxage)()                                                                                                | Returns the maximum age of the cookie, specified in seconds.                                |
| [getName](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#getname)()                                                                                                    | Returns the cookie's name.                                                                  |
| [getPath](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#getpath)()                                                                                                    | Returns the path for the cookie.                                                            |
| [getSecure](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#getsecure)()                                                                                                | Identifies if the cookie is secure.                                                         |
| [getValue](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#getvalue)()                                                                                                  | Returns the cookie's value.                                                                 |
| ~~[getVersion](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#getversion)()~~                                                                                          | Returns the version that was previously set for this cookie.                                |
| [isHttpOnly](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#ishttponly)()                                                                                              | Identifies if the cookie is http-only.                                                      |
| ~~[setComment](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setcommentstring)([String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md))~~  | Sets a comment associated with this cookie.                                                 |
| [setDomain](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setdomainstring)([String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md))        | Sets the domain associated with the cookie.                                                 |
| [setHttpOnly](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#sethttponlyboolean)([Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)) | Sets the http-only state for the cookie.                                                    |
| [setMaxAge](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setmaxagenumber)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md))        | Sets the maximum age of the cookie in seconds.                                              |
| [setPath](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setpathstring)([String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md))            | Sets the path for the cookie.                                                               |
| [setSecure](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setsecureboolean)([Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md))     | Sets the secure state for the cookie.                                                       |
| [setValue](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setvaluestring)([String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md))          | Sets the cookie's value.                                                                    |
| ~~[setVersion](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setversionnumber)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md))~~  | Returns the version that was previously set for this cookie.                                |

### Methods inherited from class Object

[assign](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#assignobject-object), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject-object), [defineProperties](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertiesobject-object), [defineProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertyobject-object-object), [entries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#entriesobject), [freeze](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#freezeobject), [fromEntries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#fromentriesiterable), [getOwnPropertyDescriptor](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertydescriptorobject-object), [getOwnPropertyNames](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertynamesobject), [getOwnPropertySymbols](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertysymbolsobject), [getPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getprototypeofobject), [hasOwnProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#hasownpropertystring), [is](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isobject-object), [isExtensible](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isextensibleobject), [isFrozen](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isfrozenobject), [isPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isprototypeofobject), [isSealed](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#issealedobject), [keys](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#keysobject), [preventExtensions](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#preventextensionsobject), [propertyIsEnumerable](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#propertyisenumerablestring), [seal](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#sealobject), [setPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#setprototypeofobject-object), [toLocaleString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tolocalestring), [toString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tostring), [valueOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valueof), [values](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valuesobject)

## Constant Details

### EMPTYNAME

- EMPTYNAME: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) = "dw_emptyname\_\_"
  - : Default name for cookies with empty strings.

***

## Property Details

### comment

- ~~comment: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)~~
  - : Returns the comment that was previously set for this cookie, or null if no comment was set. Note that comments
    are no longer supported in RFC 6265 and will not be sent to clients. This method is maintained for backward
    compatibility only.

    **Deprecated:**

:::warning
This method is maintained for backward compatibility only. Cookie comments were removed in RFC 6265
and are no longer sent to clients. The returned value only reflects what was previously set using
[setComment(String)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setcommentstring).
:::

```
**API Version:**
```

:::note
This method is deprecated and will be removed in the next API version.
:::

***

### domain

- domain: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns the domain associated with the cookie.

***

### httpOnly

- httpOnly: [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Identifies if the cookie is http-only.

***

### maxAge

- maxAge: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)
  - : Returns the maximum age of the cookie, specified in seconds.
    By default, -1 indicating the cookie will persist until client shutdown.

***

### name

- name: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`
  - : Returns the cookie's name.

***

### path

- path: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns the path for the cookie.

***

### secure

- secure: [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Identifies if the cookie is secure.

***

### value

- value: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns the cookie's value.

***

### version

- ~~version: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)~~
  - : Returns the version that was previously set for this cookie. Note that the version is no longer used for
    determining cookie compliance as the system now uses RFC 6265 by default. The returned value only reflects what
    was previously set using [setVersion(Number)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setversionnumber).

    **Deprecated:**

:::warning
This method is maintained for backward compatibility only. The version property is no longer used as
the system now uses RFC 6265 compliance by default. The returned value has no effect on cookie
behavior.
:::

```
**API Version:**
```

:::note
This method is deprecated and will be removed in the next API version.
:::

***

## Constructor Details

### Cookie(String, String)

- Cookie(name: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md), value: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md))
  - : Constructs a new cookie using the specified name and value.

    **Parameters:**

    - name - the name for the cookie.
    - value - the cookie's value.

***

## Method Details

### getComment()

- ~~getComment(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)~~
  - : Returns the comment that was previously set for this cookie, or null if no comment was set. Note that comments
    are no longer supported in RFC 6265 and will not be sent to clients. This method is maintained for backward
    compatibility only.

    **Returns:**

    - the comment that was previously set, or null if no comment was set

    **Deprecated:**

:::warning
This method is maintained for backward compatibility only. Cookie comments were removed in RFC 6265
and are no longer sent to clients. The returned value only reflects what was previously set using
[setComment(String)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setcommentstring).
:::

```
**API Version:**
```

:::note
This method is deprecated and will be removed in the next API version.
:::

***

### getDomain()

- getDomain(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns the domain associated with the cookie.

    **Returns:**

    - the domain associated with the cookie.

***

### getMaxAge()

- getMaxAge(): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)
  - : Returns the maximum age of the cookie, specified in seconds.
    By default, -1 indicating the cookie will persist until client shutdown.

    **Returns:**

    - an integer specifying the maximum age of the cookie in seconds;
      if negative, means the cookie persists until client shutdown

***

### getName()

- getName(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns the cookie's name.

    **Returns:**

    - the cookie's name.

***

### getPath()

- getPath(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns the path for the cookie.

    **Returns:**

    - the path for the cookie.

***

### getSecure()

- getSecure(): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Identifies if the cookie is secure.

    **Returns:**

    - true if the cookie is secure, false otherwise.

***

### getValue()

- getValue(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns the cookie's value.

    **Returns:**

    - the cookie's value.

***

### getVersion()

- ~~getVersion(): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)~~
  - : Returns the version that was previously set for this cookie. Note that the version is no longer used for
    determining cookie compliance as the system now uses RFC 6265 by default. The returned value only reflects what
    was previously set using [setVersion(Number)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setversionnumber).

    **Returns:**

    - the version number that was set, or 0 if no version was explicitly set

    **Deprecated:**

:::warning
This method is maintained for backward compatibility only. The version property is no longer used as
the system now uses RFC 6265 compliance by default. The returned value has no effect on cookie
behavior.
:::

```
**API Version:**
```

:::note
This method is deprecated and will be removed in the next API version.
:::

***

### isHttpOnly()

- isHttpOnly(): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Identifies if the cookie is http-only.

    **Returns:**

    - true if the cookie is http-only, false otherwise.

***

### setComment(String)

- ~~setComment(comment: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)): void~~
  - : Sets a comment associated with this cookie. Note that comments are no longer sent to clients as they were removed
    in RFC 6265. This method is maintained for backward compatibility but has no effect on the cookie's behavior.

    **Parameters:**

    - comment - the comment to associate with the cookie (ignored)

    **Deprecated:**

:::warning
This method is maintained for backward compatibility only. Cookie comments were removed in RFC 6265
and will not be sent to clients. The value will be stored but has no effect on cookie behavior.
:::

```
**API Version:**
```

:::note
This method is deprecated and will be removed in the next API version.
:::

***

### setDomain(String)

- setDomain(domain: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)): void
  - : Sets the domain associated with the cookie.

    **Parameters:**

    - domain - the comment associated with the cookie.

***

### setHttpOnly(Boolean)

- setHttpOnly(httpOnly: [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)): void
  - : Sets the http-only state for the cookie.

    **Parameters:**

    - httpOnly - sets http-only state for the cookie.

***

### setMaxAge(Number)

- setMaxAge(age: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): void
  - : Sets the maximum age of the cookie in seconds.

    A positive value indicates that the cookie will expire after that many
    seconds have passed. Note that the value is the maximum age when the
    cookie will expire, not the cookie's current age.

    A negative value means that the cookie is not stored persistently and
    will be deleted when the client exits. A zero value causes the
    cookie to be deleted.

    **Parameters:**

    - age - an integer specifying the maximum age of the cookie in seconds;             if negative, means the cookie is not stored; if zero, deletes             the cookie

***

### setPath(String)

- setPath(path: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)): void
  - : Sets the path for the cookie.

    **Parameters:**

    - path - the path for the cookie.

***

### setSecure(Boolean)

- setSecure(secure: [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)): void
  - : Sets the secure state for the cookie.

    **Parameters:**

    - secure - sets secure state for the cookie.

***

### setValue(String)

- setValue(value: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)): void
  - : Sets the cookie's value.

    **Parameters:**

    - value - the value to set in the cookie.

***

### setVersion(Number)

- ~~setVersion(version: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): void~~
  - : Returns the version that was previously set for this cookie. Note that the version is no longer used for
    determining cookie compliance as the system now uses RFC 6265 by default. The returned value only reflects what
    was previously set using [setVersion(Number)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Cookie.md#setversionnumber).

    **Returns:**

    - the version number that was set, or 0 if no version was explicitly set

    **Deprecated:**

:::warning
This method is maintained for backward compatibility only. The version property is no longer used as
the system now uses RFC 6265 compliance by default. The returned value has no effect on cookie
behavior.
:::

```
**API Version:**
```

:::note
This method is deprecated and will be removed in the next API version.
:::

***
