Archive for the Category ColdFusion

 
 

ColdFusion: Delete a Cookie.

Most sources will tell you that in order to delete a cookie using cfcookie, that you need to set it’s expiry time to ‘NOW’.

<cfcookie name="source_id" expires="Now">

For some reason, this seems kludgy to me. Are the browser and the web server going to agree as to what the meaning of ‘Now’ really is?

I prefer a more concrete approach.


<cfset result = StructDelete(cookie, "source_id")>

No if, ands, or buts here. That cookie is toast. At least at the ColdFusion app server level. The cookie still exists on the users machine. But the app server is unaware of this, since it’s internal representation of the cookie has been destroyed, and won’t be rebuilt again unless the cookie is explicitly reset. To be sure, using both methods in conjunction with one another is a safe bet.

ColdFusion: Looping Through A List

How to loop through a comma-delimited list.


<!— create string —>

<cfset lValues = "one,two,three,four">

<!— output strings —>

<cfloop list="#lValues#" index="i">

 <cfoutput>

  #i#

 </cfoutput>

</cfloop>

ColdFusion: Splitting Strings

While ColdFusion itself offers no convenient form of splitting strings, the underlying JVM offers such capability, with much ease of use. Take this example:

<!--- create string --->

<cfset lValues = "one,two,three,four">

<!--- split string --->

<cfset lArray = lValues.split(",")>

<!--- output strings --->

<cfoutput>

#lArray[1]# would print out 'one'

#lArray[2]# would print out 'two'

#lArray[3]# would print out 'three'

#lArray[4]# would print out 'four'

</cfoutput>