Solved

Deleting a dynamically named cookie

Posted on 2013-06-27
11
301 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
ID: 39282548
(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
ID: 39282560
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
ID: 39282569
Use array notation:

       <cfoutput>#cookie[ theDynamicCookieName ]#</cfoutput>
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

Author Comment

by:CFbubu
ID: 39282577
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
ID: 39282604
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
 

Author Comment

by:CFbubu
ID: 39282661
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_
ID: 39282828
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
ID: 39282830
Thank you _agx_ .
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39282879
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
ID: 39282946
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_
ID: 39283294
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: 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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