|
| 1 | +--- |
| 2 | +icon: cookie |
| 3 | +category: http-responses |
| 4 | +summary: Set a cookie in the visitor's browser. |
| 5 | +top: |
| 6 | + - name: domain |
| 7 | + type: TEXT |
| 8 | + description: The domain for which the cookie will be sent. If not specified, the cookie will be sent for |
| 9 | + all domains. |
| 10 | + - name: expires |
| 11 | + type: TIMESTAMP |
| 12 | + description: The date at which the cookie expires (either a timestamp or a date object). If not specified, |
| 13 | + the cookie will expire when the browser is closed. |
| 14 | + - name: http_only |
| 15 | + type: BOOLEAN |
| 16 | + description: Whether the cookie should only be accessible via HTTP and not via client-side scripts. If |
| 17 | + explicitly set to false, the cookie will be accessible via both HTTP and client-side scripts. |
| 18 | + - name: max_age |
| 19 | + type: INTEGER |
| 20 | + description: The maximum age of the cookie in seconds. number of seconds until the cookie expires. If both |
| 21 | + Expires and Max-Age are set, Max-Age has precedence. |
| 22 | + - name: name |
| 23 | + type: TEXT |
| 24 | + required: true |
| 25 | + description: The name of the cookie to set. |
| 26 | + - name: path |
| 27 | + type: TEXT |
| 28 | + description: The path for which the cookie will be sent. If not specified, the cookie will be sent for |
| 29 | + all paths. |
| 30 | + - name: remove |
| 31 | + type: BOOLEAN |
| 32 | + description: Set to TRUE to remove the cookie from the client browser. When specified, other parameters |
| 33 | + are ignored. |
| 34 | + - name: same_site |
| 35 | + type: TEXT |
| 36 | + description: Whether the cookie should only be sent for requests originating from the same site. See owasp.org/www-community/SameSite. |
| 37 | + `strict` is the recommended and default value, but you may want to set it to `lax` if you want your users |
| 38 | + to keep their session when they click on a link to your site from an external site. |
| 39 | + - name: secure |
| 40 | + type: BOOLEAN |
| 41 | + description: Whether the cookie should only be sent over a secure (HTTPS) connection. Defaults to TRUE. |
| 42 | + - name: value |
| 43 | + type: TEXT |
| 44 | + description: The value of the cookie to set. |
| 45 | +--- |
| 46 | + |
| 47 | +Sets a cookie in the client browser, used for session management and storing user-related information. |
| 48 | + |
| 49 | +This component creates a single cookie. Since cookies need to be set before the response body is sent to the client, |
| 50 | +this component should be **placed at the top of the page**, before any other components that generate output. |
| 51 | + |
| 52 | +After being set, a cookie can be accessed anywhere in your SQL code using the `sqlpage.cookie('cookie_name')` pseudo-function. |
| 53 | + |
| 54 | +Note that if your site is accessed over HTTP (and not HTTPS), you have to set `false as secure` to force browsers to accept your cookies. |
0 commit comments