Possible Duplicate:
Calling a variable with a variable in its name – coldfusion?
Sorry, I’m a bit of a newbie at Coldfusion. Trying to update some legacy code at work…
I named a cookie in coldfusion using a variable.
<cfcookie name="#FORM.cookie_name#" Expires="#FORM.cookie_expires#">
How do I check to see if the cookie hasn’t expired? This seems to crash the page…
<cfif isDefined("cookie.#FORM.cookie_name#")>
Many thanks.
To check if it exists, use StructKeyExists:
To use the variable, use bracket notation:
Don’t forget both Form variables and Cookie variables are submitted by the user/client – and thus must be treated appropriately (i.e. never trust that they contain what you think they do, because it’s not guaranteed).
Note, if you did want to use the isDefined form to do this (though there’s benefit to it), it would need to be written like so:
Which would then be evaluated as
Cookie['606ac80d']– without those single quotes it would be an invalid variable.As noted by Leigh, the above works in Railo and OpenBD, but not in Adobe ColdFusion, where you would need to write:
This syntax will work for simple alphanumeric variable names, but specifically may cause issues if form.cookie_name contained a value with a
.in.