问题
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:
Does StructDelete actually just set blank values? Or have I missed something obvious and simple... again
回答1:
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.
来源:https://stackoverflow.com/questions/8508433/coldfusion-structdelete-creates-blank-value