| home -> documentation -> language reference -> SETCOOKIE tag |
Description
The SETCOOKIE tag allows to store a variable in the client web browser (as
a browser cookie) for the entire session or any specified time.
Syntax
| <#SETCOOKIE NAME="aname" VALUE="avalue"
| EXPRESSION="anexpression" | PATTERN="apattern" [EXPIRES="exptime"]> |
| NAME |
Specify on aname the name of
the variable. This property is case insensitive. |
| VALUE |
Specify in avalue the value that
you want to store on the variable. |
| EXPRESSION |
You can specify in anexpression an arithmetic
expression. The DBSP engine will evaluate the expression first and the result
will be stored in the value property. If you want to know about this feature,
see arithmetic expressions. |
| PATTERN |
You can use this property to extract
prefixes, infixes or suffixes of strings and then store it as the variable
value. If you want to know more about this feature, see String
patterns. |
| EXPIRES |
Use this property to specify the time
that the variable will remain active on the user's browser after the page
be loaded. This is a real value: 1 means 24 hours after the page is loaded
and 1.5 means 36 hours after the page is loaded. |
Considerations
- The variable names are case insensitive.
- If the variable name previously exist, the old value will be replaced with
the new one.
- The user must have the cookies activated on his browser in order this tag works properly.
Applications
The SETCOOKIE tag is useful when you need to store a value commonly used in
several pages on the system.
Another application of the SETCOOKIE tag is to store a value for more than
the session time (the time that the web browser remains open). This is useful
for example, when you want to remember the user identification and preferences,
in order to bring a more comfortable user experience.
Examples
Example 1. Storing the background color in a cookie.
This examples shows how to store a value selected by the user with the SETCOOKIE tag an use it in a subsequent page.
Source code
File: operativeexamples/SetCookie/SetCookie.dbsp
<#IF EXPRESSION="cbxCOLORS=UNDEF"> <#ELSE> <#SETCOOKIE NAME="COOKIEBACKGROUND" EXPRESSION="cbxCOLORS"/> <#/IF> Storing the background color in a cookie Background color: <#COOKIEBACKGROUND/> Customize the background
|
File: OperativeExamples/SetCookie/SetCookieBK.dbsp
Test example
|