Copy link to clipboard
Copied
I set cookies like this:
<cfcookie name="ckwhatever" value="hello">
I try to kill the cookie like this:
<cfcookie name="ckwhatever" expires="now">
This does NOT work. the cookie remains.
I've tested on mozilla and IE
I don't get it.
Copy link to clipboard
Copied
When you say it "remains", do you mean the cookie physically stays on the client PC, or you can still reference the variable in the COOKIE scope?
From the docs: "deletes cookie from client cookie.txt file (but does not delete the corresponding variable the Cookie scope of the active page)."
Copy link to clipboard
Copied
Yes it was still available in scope.
But once I added the domain attribute it worked. Weird. I've never used that before, not sure why it was necessary now. It's all on the same domain.
Copy link to clipboard
Copied
If you're using domain cookies then you'll need to use it here too. I.e. the domain of the cookie you're deleting will need to match up exactly with the CFCOOKIE delete statement.
Copy link to clipboard
Copied
You can use structDelete(cookie,"ckwhatever",true) to clear the cookie structure.
Copy link to clipboard
Copied
True, but that won't remove the cookie from the user's browser, so the variable will come back on the next request.
Copy link to clipboard
Copied
It amazes me that coldfusion has no native way to truly just get rid of a cookie you created from the computer and from the page.
Copy link to clipboard
Copied
It does, you just did it?
Copy link to clipboard
Copied
To test wheather we can delete the cookie variable or not i have performed the following steps.
Page Name:setcookie.cfm
Note:I am setting cookie in this page.
Code:<cfcookie name="mytestcookie" value="testvalue" expires="never">
<cfdump var="#cookie#">
<a href="killcookie.cfm">kill</a>
Output:
struct | |
|---|---|
| MYTESTCOOKIE | testvalue |
Page Name:killcookie.cfm
Note:I am deleting and viewing cookie in this page.
Code:<!--- check wheather cookie exist or not --->
<cfdump var="#cookie#"><br>
<!--- here i am going to delete cookie --->
deleting cookie<br>
<cfcookie name="mytestcookie" expires="#now()#">
<!--- dumping after deleting --->
<cfdump var="#cookie#">
<a href="result.cfm">result</a>
output:
| struct | |
|---|---|
| MYTESTCOOKIE | testvalue |
| struct | |
|---|---|
| MYTESTCOOKIE | [empty string] |
Page Name:result.cfm
Code:<cfdump var="#cookie#">
Output:
struct [empty]
I think after setting expires attr in cfcookie tag the cookie variable is not getting deleted in that page.
Copy link to clipboard
Copied
I think after setting expires attr in cfcookie tag the cookie variable is not getting deleted in that page.
Which is a bit like what I quoted earlier from the docs:
"deletes cookie from client cookie.txt file (but does not delete the corresponding variable the Cookie scope of the active page)."
Copy link to clipboard
Copied
yes you are right. I just explained.
Copy link to clipboard
Copied
I am experiencing issues with cookie killing as well so I read through this post. I tried to utilize the domain attribute and that didn't make a difference. I cannot remove my cookie from the local pc. Frustrating. I never used to have problems with this and it seems to work just fine in Firefox. I am currently experiencing the problem using IE 7 (go figure).
The cookie is set like this in the Application.cfm
<cfcookie domain=www.mydomain.com name="mycookie" value="testing" expires="Never">
Here is my cookie removal code. When a user clicks "Logout" on my site they get directed to logout.cfm which contains the code below...
<cfcookie domain=www.mydomain.com name="mycookie" value="" expires="NOW">
<cfset delete_cookie=StructDelete(cookie,"mycookie")>
<cflogout>
<cflocation url="home.cfm">
Copy link to clipboard
Copied
What version of ColdFusion are you using?
Would it be possible for you to capture and post the request and response headers for the cookie set and cookie kill?
Copy link to clipboard
Copied
Version: cf9
I will attempt to do that but am not sure how. Firebug? If firebug, how specifically.
Thx
Copy link to clipboard
Copied
I would use the firefox plugin called HTTP Live Header. It is great for that kind of stuff
Copy link to clipboard
Copied
I know this is an older thread, but it's probably going to be helpful for others reading. In reply #11 above, the last line is a <cflocation> - this will essentially ignore any cookie changes made on the page. You'll either need to do a cfheader or a javascript location.href to keep your cookie changes in place.
Copy link to clipboard
Copied
Sorry to bust your bubble, but that cfcookie/cflocation behavior you are talking about was fixed something like 10 years ago (CF6, I believe). You've been able to put the two on the same page for a Loooooong time. Go ahead and try it.
Update: Here is the page in the CFWACK 7 to back that up.
CFWACK 7 Page 1008
jason
Copy link to clipboard
Copied
Thanks for the smart-@ss reply (bust my bubble). I'll check it out. I know I'd had major headaches in the past regarding this so I posted. My bad.
Copy link to clipboard
Copied
Cflocation hasn't undine cookie changes for me but I'll go check again.
Sent from my iPhone
Copy link to clipboard
Copied
There's no need to check again. Like I said, that behavior no longer exists.
jason
Copy link to clipboard
Copied
I too have had problems resetting cookies on various browsers even with CF 9. What I've found seems to work every time is to delete the cookie, and then reset it, for example:
<!--- THIS SEQUENCE WORKS RELIABLY --->
<cfset delete_cookie=StructDelete(cookie,"member_ID")>
<cfcookie name="member_ID" value="0" domain=".phenom.aero" expires="never">
Simply resetting or expiring the cookie does not work reliably, for example:
<!--- NONE OF THESE WORK RELIABLY --->
<cfcookie name="member_ID" value="0" domain=".phenom.aero" expires="never">
<cfset cookie.member_ID = 0>
<cfcookie name="member_ID" value="0" domain=".phenom.aero" expires="now">
Can anybody tell me why? Am I missing something really simple here?
Copy link to clipboard
Copied
I just got this to work in an older version of Coldfusion(5). We will be migrating soon. Does this work in your version?
<cfif IsDefined("Cookie.YourCookieName")>
<cfcookie name="YourCookieName" value = "#Now()#" Expires="now" domain=".YourDomainName.com">
<cfset delete_cookie=StructDelete(cookie,"YourCookieName")>
<cfoutput>"Cookie is Gone"</cfoutput>
<cfabort>
<cfelse>
<cfcookie name="YourCookieName" value = "#Now()#" Expires="never" domain=".YourDomainName.com">
<cfoutput>"Cookie exists"</cfoutput>
<cfabort>
</cfif>
I put this after <CFAPPlication> with
<cfapplication
name = "YourAPPName"
clientmanagement="yes"
sessionmanagement="yes"
setclientcookies="yes"
sessiontimeout="#CreateTimeSpan(0, 0, 30, 0)#"
applicationtimeout="#CreateTimeSpan(0, 0, 30, 0)#" clientstorage="Registry"
>
To test it, I reload the page. It alternates between the "Cookie is Gone" and "Cookie exists". Let me know if that works for you.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more