Go Premium for a chance to win a PS4. Enter to Win

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

Deleting a dynamically named cookie

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
CFbubu
Asked:
CFbubu
  • 6
  • 5
2 Solutions
 
_agx_Commented:
(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
 
CFbubuAuthor Commented:
Thanks..i will try it again.

Btw, how would I get out the value of the dynamically named cookie in a <cfoutput> tag?
0
 
_agx_Commented:
Use array notation:

       <cfoutput>#cookie[ theDynamicCookieName ]#</cfoutput>
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
CFbubuAuthor Commented:
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
 
CFbubuAuthor Commented:
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
 
CFbubuAuthor Commented:
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
 
_agx_Commented:
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
 
CFbubuAuthor Commented:
Thank you _agx_ .
0
 
_agx_Commented:
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
 
CFbubuAuthor Commented:
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
 
_agx_Commented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now