Wednesday, November 28, 2012

Setting Cookie by cfscript in ColdFusion 10

Now a days in ColdFusion coding most of us generally using script version of CF more than tag version. Sometimes we feel upset when we don't get the script version for a particular tag. In  such cases we write our own function to use that in script code. CFCOOKIE is one tag which used to set cookie and which doesn't have any script version before ColdFusion 10.

   In ColdFusion 10, script version for CFCOOKIE  introduced. We can set cookie by cfscript in ColdFusion 10 as follows.


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

Followers