AIX | HP-UX | Linux | OS/2 | OS/390 | OS/400 | SCO | SUN | Win NT |
X | X | X | X | X | X | X | X | X |
Purpose
Generates JavaScript code that sets a cookie on the client system.
Format
@DTW_SETCOOKIE(IN cookie_name, IN cookie_value, IN advanced_options)
@DTW_SETCOOKIE(IN cookie_name, IN cookie_value)
Parameters
Table 47. DTW_SETCOOKIE Parameters
Data Type | Parameter | Use | Description |
---|---|---|---|
string | cookie_name | IN | A variable or literal string that specifies the name of the cookie |
string | cookie_value | IN | A variable or literal string the specifies the value of the
cookie.
Avoid using semicolons, commas, and spaces as a part of cookie_value. When they are required, use the Net.Data function DTW_rURLESCSEQ to process the string that contains the special characters before passing it to DTW_SETCOOKIE. For example, @DTW_SETCOOKIE("my_cookie_name", @DTW_rURLESCSEQ("my cookie value")) |
string | advanced_options | IN | A string that contains optional attributes, separated by semicolons, that
are used to define the cookie. These attributes can be:
For additional information about the advanced options, see the Netscape cookie specification at http://home.netscape.com |
Return Codes
Table 48. DTW_SETCOOKIE Return Codes
Return Code | Explanation |
---|---|
-1001 | The server could not process a Net.Data request to allocate memory. |
1001 | An input parameter contained a NULL value. |
1002 | An input parameter contained a string value which consisted of the null-terminating character. |
1003 | The number of parameters passed on a function call either exceeded the maximum number allowed, or was less than the minimum number required by the function. |
1005 | A parameter passed on a function call, required to be a string variable, was of a different variable type. |
Usage Notes
Examples
Example 1: Defines cookies that contain user ID and password information with the Secure advanced option
@DTW_SETCOOKIE("mycookie_name_for_userID", "User1") @DTW_SETCOOKIE("mycookie_name_for_password", "sd3dT", "secure")
Example 2: Defines cookies that contain the expiration date advanced option
@DTW_SETCOOKIE("mycookie_name_for_userID", "User1", "expires=Wednesday 01-Dec-2010 00:00:00") @DTW_SETCOOKIE("mycookie_name_for_password", "sd3dT", "expires=Wednesday, 01-Dec-2010 00:00:00;secure")
Function calls should be on one line; the lines are split in this example for formatting purposes.
Example 3: Determines if a cookie for a user exists before gathering user information
%HTML(welcome) { <html> <body> <h1>Net.Data Club</h1> @DTW_GETCOOKIE("NDC_name", name) %IF ($(RETURN_CODE) == "8000") %{ The cookie is not found. %} <form method="post" action="remember"> <p>Welcome to the club. Please enter your name.<br> <input name="name"> <input type="submit" value="submit"><br> </form> %ELSE <p>Hi, $(name). Welcome back. %ENDIF </body> </html> %}
The HTML(welcome) section checks whether the cookie NDC_name exists. If the cookie exists, the browser displays a personalized greeting. If the cookie does not exist, the browser prompts for the user's name, and posts it to the HTML(remember) section. This section records the user's name into the cookie NDC_name as shown below:
%HTML(remember) { <html> <body> <H1>Net.Data Club> @DTW_SETCOOKIE("NDC_name", name, "expires=Wednesday, 01-Dec-2010 00:00:00;path=/") <p>Thank you. <p><a href="welcome">Come back</a> </body> </html> %}