3

I'm using Codlfusion 9's StructDelete() method to remove a value from a cookie. But after using

StructDelete(cookie,"selector12")

I'm getting a value of [empty string] for cookie.selector12 despite deleting it

This is the code I'm using:

<cfdump var="#cookie#">
<!--- kill any existing selector cookie when looking at a profile --->
<cfset structDelete(cookie,'selector#URL.clk#')>
<cfdump var="selector#URL.clk#">
<cfdump var="#cookie#">

To give the following output:

Screen shot of cookie cfdumps

Does StructDelete actually just set blank values? Or have I missed something obvious and simple... again

1 Answer 1

8

The behavior of StructDelete() when applied to the COOKIE structure pushes the following header to your browser:

Set-Cookie SELECTOR12=;expires=Wed, 14-Dec-2011 10:06:02 GMT;path=/

which in turn will (for the remainder of the life of that request) produce a browser cookie with a blank value -- which mimics the behavior you're seeing when calling cfdump on that COOKIE structure.

This is simply a side-effect of dealing with the COOKIE structure, which in reality, wraps access to your browser's cookies--and is therefore limited by how cookies are defined/managed in web-browsers.

2
  • Thank you Holmes. Living up to your name there. I guess I'll have to work around that then, cheers.
    – Pete
    Dec 14, 2011 at 17:13
  • 2
    Would help to use <cfcookie name="selector#URL.clk#" expires="now"> instead of or in addition to the structDelete?
    – ale
    Dec 14, 2011 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.