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

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

Tricky Coldfusion Cookie Question

Hi,

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:

#cookie.cookiename#

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.

<cfoutput>#cookie.super12345#</cfoutput>

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

<cfoutput>#cookie.super#cname##</cfoutput>


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!
0
CFbubu
Asked:
CFbubu
  • 3
  • 2
1 Solution
 
_agx_Commented:
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>
0
 
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 :)
0
 
_agx_Commented:
No problem, take your time.  (Always nice when the answer is simpler than you think it'll be, instead of the other way around ;-)
0
 
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.:)

Regards

p.s. - forgot to add.....and so fast to respond to my cry for help...;)
0
 
_agx_Commented:
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 :)
0

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