Question: Same cookie, different values between ColdFusion and JavaScript


Same cookie, different values between ColdFusion and JavaScript

Answers 1
Added at 2016-12-23 17:12

I am running into a problem with a cookie I want to access with both JavaScript and CF. I can create the cookie with JavaScript, like so:

document.cookie = 'SAVEDLISTINGS='+newc + ';path=/';

and on the next page CF can see it fine. However, if I use the same JavaScript to update the cookie with a new value, CF will not detect the change on subsequent pages. It retains its original value, as evidenced by the debug output and by dumping the Cookie scope.

JavaScript continues to see the correct cookie value, which I can check using Firefox developer tools. I assume this means the cookie file is being correctly updated. I do not see two cookies with the same name: only one, and it has the value as manipulated by the JavaScript.

I can delete the cookie in JavaScript, using

document.cookie = 'SAVEDLISTINGS=; expires=Thu, 01 Jan 1970 00:00:00 UTC' + ';path=/';

and this will delete the cookie from CF as well (on subsequent pages).

Note that I am not actually using CFCookie to manage the cookie, but I have experimented with setting it blank by ColdFusion (with httponly=no). This doesn't seem to make any difference.

Answers to

Same cookie, different values between ColdFusion and JavaScript

nr: #1 dodano: 2016-12-24 16:12

Set the domain value of the cookie to make sure you are getting/setting the same exact cookie. You can view that info with Firebug. You can see below how two cookies named "testName" are treated as separate entities based on the domain. This is important so different sites can have the same cookie names without overwriting each other.

enter image description here

Source Show
◀ Wstecz