Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

Tricky Coldfusion Cookie Question


I have a quick question about the setting and use of a cookie.

Let say I have a variable 'cname' which I set value as '12345'

To create a 'dynamically' named cookie, I combine the 'cname' variable to the cookie creation tag(See code lines below)

<cfset cname = '12345'>

<cfcookie name="super#cname#" value="999" expires="1">

The question I have here is, how do I access the value of the dynamicly named cookie?

Normally to access the value of a cookie, we call it like thus:


But in the above example, how do I access the value of the 'dynamically' named cookie with a value of 999?

If I accessed the cookie using the method below, it will work, but I want to place the dynamic call to the cookie without hardcoding the '12345' into the call.


How do I somehow call the cookie value above with the dynamic name inside like below without an error?


Is this possible?

(I know that I can create the cookie and place the 'dynamic' value right inside the value ="" spot, but I want to be able to name a cookie dynamically as I want the cookie to have a unique name for keeping track purposes)

Thanks alot!
  • 3
  • 2
1 Solution
Nice thing about CF is most all scopes are structures. So dynamic key names are easy. Use associative array notation  ie   scopeName["fixedPart"& dynamicPart]

Try using

      <cfoutput>#cookie["super#cname#"]#</cfoutput> ... OR
      <cfoutput>#cookie["super"& cname]#</cfoutput>
CFbubuAuthor Commented:
HOORAY for _agx_!

I have not tried out your solution yet...as I now have to rush out for about 45mins, but I will be back to try out your great teachings...yet always again!

I am happy as your teachings will most likely work...as they always do! Thanks for getting back to me so quick! THANKS!

Let me return again in about 45mins to 1 hour to let you know how it went :)
No problem, take your time.  (Always nice when the answer is simpler than you think it'll be, instead of the other way around ;-)
CFbubuAuthor Commented:
Dear _agx

You got it again!

 I was puzzling about this all long weekend....and in the blink of an eye, you resolved it!

Thank you so much my friend for always being so kind and generous with your knowledge.:)


p.s. - forgot to add.....and so fast to respond to my cry for help...;)
Glad to help when I can :) I think every CF-er scratches their head about dynamic variables at first. I did too. Once you realize all scopes are structures (form, url, session, application, request, xml, etc...) a lightbulb goes on. "Ha! I can do anything dynamically!". Ok... not everything, but most things :)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now