Cookies are a great way to remember visitors, and to store variables from page to page.
numero = 180[setcookie name=cookieName&value=cookieValue&expires=expireDate&path=/&domain=yourdomain.com]Putting a [setcookie] tag into a template causes the remote browser to create or replace a cookie of that name in its local list of cookies. You can use [getcookie] or [listcookies] later to retrieve that value from the remote browser. The expiration date of the cookie must be of the form Wednesday, 09-Nov-1999 23:12:40 GMT. The domain must be the name of the domain being served, otherwise the browser will not provide the cookie information.Example:
[setcookie name=Member&value=T&expires=Wednesday, 09-Nov-2008 23:12:40 GMT&path=/&domain=yourdomain.com]or one that expires 7 days from today (the +05:00:00 handles the US East Coast time difference from GMT):
[setcookie name=cart&value=32515983408&expires=[format days_to_date %A, %d-%b-%Y][math]{[date]}+7[/math][/format] [math time]{[time]}+{05:00:00}[/math] GMT&path=/&domain=yourdomain.com](Configuring the messy code of the expires value is an excellent job for a global [function].)If you do not specify an expires parameter, then the cookie becomes a "session cookie," expiring automatically when the browser quits. That is, omit "expires=" altogether; don't set it with a null value - that will fail.The default value for path, '/', will allow any template on the website to access the cookie. You can, however, confine a cookie to a specific directory. For instance, if you specify a path value of '/admin/', then only templates within the '/admin' directory can access the cookie.Setting the domain parameter limits which subdomain may access the cookie. If you specify 'www.yourdomain.com', then only templates within that subdomain can access the cookie. Specifying just 'yourdomain.com' for the domain, will allow templates from 'www.yourdomain.com', 'secure.yourdomain.com', or 'whatever.yourdomain.com' to all access the cookie.RETRIEVING COOKIES[getcookie name=cookieName]Displays the value of the cookie named "member" that the remote browser has remembered. If no cookie of that name exists, then nothing (a blank value) is returned. [ listcookies params]Cookie Tags[/listcookies]ListCookies lists all the cookie names and values sent from the remote browser. ListCookies is very helpful when writing code using cookies, to see if and when cookies are being set.Example:The following are all the cookies available to this page:<br>
[listcookies][index], [name], [value]<br>[/listcookies]The [listcookies] context has optional parameters to modify the list of cookies produced. To list the cookies whose name begins with "text":
[listcookies name=text&exact=F][index],[value]<br>[/listcookies]
Parameter | Description |
---|---|
Name | (optional) The name of the cookie to list. |
Exact | T or F (optional) Whether to exactly match the cookie name or return any cookie name that contains the "name" value. (Default value is T.) |
Tag | Description |
---|---|
[name] | The name of the cookie. |
[value] | The value associated with the cookie. |
[index] | A number indicating this cookie's placement in the list. |
It is important to understand that when you set a cookie on a page, it is NOT available via [getcookie] further down in the same page. Only when the user accesses the NEXT page does the cookie become available. For this reason, [redirect [thisurl]] is often used immediately after setting a cookie to make it available.
Parameter | Description |
---|---|
HttpOnly | (optional) HttpOnly should be T, just like Secure. It adds a HttpOnly to the cookie, and treats everything else as a F. |
MaxAge | MaxAge should be a date just like Expires. It adds a Max-Age= to the cookie |
Raw | RAW lets you add anything you want to the cookie. You can use it conjunction with the other parameters or in place of them. You must still specify a name and value. Separate multiple raw parameters with a semi-colon and a space.For example:[setcookie name=cookieName&value=cookieValue&HttpOnly=T&Raw=domain=example.com; secure]or[setcookie name=cookieName&value=cookieValue&Raw=domain=example.com; secure; HttpOnly] |
[setcookie name=cookieName&value=cookieValue&expires=expireDate&path=/&domain=yourdomain.com]
[setcookie name=Member&value=T&expires=Wednesday, 09-Nov-2008 23:12:40 GMT&path=/&domain=yourdomain.com]
[setcookie name=cart&value=32515983408&expires=[format days_to_date %A, %d-%b-%Y][math]{[date]}+7[/math][/format] [math time]{[time]}+{05:00:00}[/math] GMT&path=/&domain=yourdomain.com]
[listcookies]
[index], [name], [value]<br>
[/listcookies]
[listcookies name=text&exact=F]
[index],[value]<br>
[/listcookies]
Parameter | Description |
---|---|
Name | (optional) The name of the cookie to list. |
Exact | T or F (optional) Whether to exactly match the cookie name or return any cookie name that contains the "name" value. (Default value is T.) |
Tag | Description |
---|---|
[name] | The name of the cookie. |
[value] | The value associated with the cookie. |
[index] | A number indicating this cookie's placement in the list. |
It is important to understand that when you set a cookie on a page, it is NOT available via [getcookie] further down in the same page. Only when the user accesses the NEXT page does the cookie become available. For this reason, [redirect [thisurl]] is often used immediately after setting a cookie to make it available.
Parameter | Description |
---|---|
HttpOnly | (optional) HttpOnly should be T, just like Secure. It adds a HttpOnly to the cookie, and treats everything else as a F. |
MaxAge | MaxAge should be a date just like Expires. It adds a Max-Age= to the cookie |
Raw | RAW lets you add anything you want to the cookie. You can use it conjunction with the other parameters or in place of them. You must still specify a name and value. Separate multiple raw parameters with a semi-colon and a space. For example: [setcookie name=cookieName&value=cookieValue&HttpOnly=T&Raw=domain=example.com; secure] or [setcookie name=cookieName&value=cookieValue&Raw=domain=example.com; secure; HttpOnly] |
DOWNLOAD WEBDNA NOW!
A list of available libraries for WebDNA...
AWS Raw WebDNA LAMP-Plus WebServerAmazon Web Services (AWS) README for Machine Image ID...
Download WebDNA ApplicationsWebDNA applications...
WebDNA ModulesA list of the currently available modules...
Tips and TricksA list of user-submitted tips ...
Technical Change HistoryThis Technical Change History provides a reverse chronological list of WebDNA changes...
Rename a folder in your webspace...
[object]Embeds the results of an external function...
[scope]Explicitly define a block of WebDNA code that has a separate variable space...
[xmlparse]Enable the WebDNA programmer to input XML data into a WebDNA variable...
[protect]...
[listfields]Lists all the fields in the specified database...