Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Deleting a dynamically named cookie

Posted on 2013-06-27
11
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 2000 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 2000 total points
ID: 39282569
Use array notation:

       <cfoutput>#cookie[ theDynamicCookieName ]#</cfoutput>
0
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

705 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