Solved

Deleting a dynamically named cookie

Posted on 2013-06-27
11
296 Views
Last Modified: 2013-06-27
Hi,

Thanks again for looking into this question of mine.

I am looking for the correct syntex to expire a dynamically named cookie.

For example, I create the cookie below:

 <cfcookie name="dynamic#right(get.jonnumber,5)#" value="dynamic#right(get.jonnumber,5)#" expires="never"/>

Now, if I am looking to expire it, how to I correctly write out the syntex?

I have tried:

<cfcookie name="#cookie["dynamic#right(get.jonnumber,5)#"]#"  value="#cookie["dynamic#right(get.jonnumber,5)#"]#"  expires="NOW" >

But the above syntex gets me an error....

Thanks alot !
0
Comment
Question by:CFbubu
  • 6
  • 5
11 Comments
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 500 total points
Comment Utility
(EDIT) What's the error?

Nothing technically wrong with it that I can see. Worked for me with a test value. Though I think it's cleaner to do something like:

<cfset name = "dynamic"& right(get.jonnumber,5)>
<cfcookie name="#cookie[name]#"  value="#cookie[name]#"  expires="NOW" >
0
 

Author Comment

by:CFbubu
Comment Utility
Thanks..i will try it again.

Btw, how would I get out the value of the dynamically named cookie in a <cfoutput> tag?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
Comment Utility
Use array notation:

       <cfoutput>#cookie[ theDynamicCookieName ]#</cfoutput>
0
 

Author Comment

by:CFbubu
Comment Utility
Thanks _agx_,

I have been having a little frustration in getting this to work still.....let me try alittle longer and see what I am doing wrong and I will get back to you.

Thanks so much for your kind watch.
0
 

Author Comment

by:CFbubu
Comment Utility
Hi,

I am still not having success with anything so far...:(

I cannot even solve the simple issue of getting the value out of the dynamicallyu named cookie in the cfoutput tags.

This is my named cookie when I created it:

<cfcookie name="nopg#right(SESSION.auth.UserID,10)#" value="nopg#right(SESSION.auth.UserID,10)#" expires="never"/>

When I try to output the created cookie value, this is the syntax I tried:

 <cfoutput>#cookie[nopg#right(SESSION.auth.UserID,10)#]#</cfoutput>

This is the error I am getting:

Invalid CFML construct found on line
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:CFbubu
Comment Utility
ok...I seem to have gotten the cfoutput tag to work with getting the cookie value:

 <cfoutput>#cookie[ 'nopg#right(SESSION.auth.UserID,10)#' ]#</cfoutput>

But now I cannot seem to expire the cookie.....aiyaya....

<cfcookie name="Cookie['nopg#right(SESSION.auth.UserID,10)#']"  value="#cookie["nopg#right(SESSION.auth.UserID,10)#"]#"  expires="NOW" >

I do not get any error message on the page, but when I do a dump of the cookies on the page, I still see it.....any idea why?

Thanks.

UPDATE

I think the cookie is not expiring because somehow the syntax of the dynamic name is not being recognised so the dynamically named cookie is not found and not being expired....I am hoping you'll be able to spot what I am writing wrong in the cookie expiration tag.

UpDate

DUH!.....I am so silly! of course the cookie expiration did not work because I was putting the 'cookie' word inside the expiration syntax! lol......

it works like this:

 <cfcookie name="nopg#right(SESSION.auth.UserID,10)#"  value="#cookie["nopg#right(SESSION.auth.UserID,10)#"]#"  expires="NOW" >

Now...I will try to use your solution to resolve the earlier questions.


Thanks
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Sorry, I got called away.  

Yep, you figured it out. You only use the word "cookie" when you're using it as a scope.

         scope["keyName"]

Like with any structure, such as URL or FORM variables:

         cookie["theNamehere"]
         URL["parameterName"]
         FORM["fieldNameHere"]
         VARIABLES["variableNameHere"]
0
 

Author Closing Comment

by:CFbubu
Comment Utility
Thank you _agx_ .
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Gah, just noticed a typo. That's what I get for testing code on one device, and typing the answer on another! This:

    <cfset name = "dynamic"& right(get.jonnumber,5)>
    <cfcookie name="#cookie[name]#"  value="#cookie[name]#"  expires="NOW" >

should've been:

    <cfset name = "dynamic"& right(get.jonnumber,5)>
    <cfcookie name="#name#"  value="#cookie[name]#"  expires="NOW" >
0
 

Author Comment

by:CFbubu
Comment Utility
Thanks for the clarification :)

Btw, I am not sure if this was also a typo, but to call out the value of a dynamically named cookie, when I tried to use your code syntax I got an error.

<cfoutput>#cookie[ theDynamicCookieName ]#</cfoutput>

So i copied and tried below and got an error.

  <cfoutput>#cookie[ nopg#right(SESSION.auth.UserID,10)# ]#</cfoutput>

However, when I added a ' after each [ ] I got it to work....like so

 <cfoutput>#cookie[ 'nopg#right(SESSION.auth.UserID,10)#' ]#</cfoutput>

But I am so glad to have you always there _agx_. I think I would have died of frustration a long time ago if you did not help :P
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Oh sorry, that was just meant to be an example :)  ... where "theDynamicCookieName" represents the name of any of your cookies.  

When you access any structure (COOKIE, FORM, URL, VARIABLES, etc...  ) you need to pass in a string - containing the name of the key you're trying to access:

                  someStructure[ "nameOfTheKeyHere" ]

There's a few ways different ways you can construct dynamic key names.

                 #cookie[ 'nopg#right(SESSION.auth.UserID,10)#' ]#
                 .. or
                 #cookie[ "nopg"& right(SESSION.auth.UserID,10) ]#
                 ... or
                 <cfset keyName = "nopg"& right(SESSION.auth.UserID,10) >
                 #cookie[ keyName ]#

.. it doesn't matter which you pick. The only thing that's important is that it resolves to a *string* containing the name of key - or in your case the cookie name.

> But I am so glad to have you always there _agx_.

Always glad to help :)  It's nice to have people to bounce ideas off of when you run into tricky coding problems.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now