In ColdFusion 10, script version for CFCOOKIE introduced. We can set cookie by cfscript in ColdFusion 10 as follows.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
/* ************** Setting Cookie by cfscript in ColdFusion 10 *********** */ | |
//Type - 1 | |
variables.cookieTest = structNew(); | |
variables.cookieTest['value'] = "This is test Cokkie by me by using cfscript"; | |
variables.cookieTest['expires'] = "10"; | |
variables.cookieTest['secure'] = "yes"; | |
variables.cookieTest['domain'] = "cf10"; | |
cookie.myNewCookie = variables.cookieTest; | |
//Type - 2 | |
cookie.yourNewCookie = {value: "This is a test cookie set by you by cfscript", expires: "10", secure: "yes", domain: "cf10"}; | |
writeDump(cookie); | |
</cfscript> |
In the above code two ways are quite similar, here we are creating a structure where the key of the structure is exactly same as the attributes of the cfcookie tag. If we are using cfscript to set cookie then we don't need to set name of the cookie in the structure as we usually do for cfcookie.
Also in ColdFusion 10, two new attributes added for setting cookie. These are follows:
preserveCase : Specify if you want to make cookie name case sensitive. This is an optional parameter and default value is "false."
encodeValue : Specify if cookie value should be encoded. This is an optional parameter and default value is "false".
Hope it will help you.
No comments:
Post a Comment