Problems deleting cookie with newLISP and Dragonfly

Started by Jeremy Reimer, November 09, 2010, 03:28:37 PM

Previous topic - Next topic

Jeremy Reimer

Hi again,



I'm building a simple web application in newlisp using the Dragonfly framework, which I really like using.  However I can't seem to delete cookies using the (Response:cookie) command.



I can set the cookie easily using this code:



(Response:cookie "monarch" username (date-value 2011 12 12) "/") ; open a cookie to say we are signed in


That makes a cookie and I can check for the presence of the cookie by searching for it in ($COOKIES), and even by searching cookies in my web browser.  It's definitely there.  The problem is that I can never get rid of it!



According to the Dragonfly reference manual, the way to get rid of the cookie is to reference it and assign it a value of "nil":



(Response:cookie "monarch" nil) ; delete cookie


But this doesn't work!  The cookie is there forever (well, until it expires in 2011).  How can I get rid of it?



I'm using newLISP 10.2.8 and Dragonfly 0.70 on Apache on Linux.

cormullion

#1
Wondering whether the cookie is cached by the browser until it restarts? Or has it just been set to have a nil value rather than be deleted? Perhaps you're supposed to set the expiry date and wait for the browser to delete it?



I've no idea, really ... :)

Jeremy Reimer

#2
I figured it out!  



I had to Google some PHP solutions to get the answer.  Apparently, you have to specify a few things:



1. The cookie should be set originally with the right domain, so



(Response:cookie "monarch" username (date-value 2011 12 12) "/" "jeremyreimer.com") ; open a cookie to say we are signed in


2. When you delete the cookie, you have to keep all the parameters the same, only change the date to some time in the past, AND, set the value to "0" (nil won't work, despite the documentation saying it will)



(Response:cookie "monarch" "0" (date-value 2009 12 12) "/" "jeremyreimer.com") ; delete cookie


Then the cookie is deleted properly.  I've tested this a bit with different names for the cookie and it seems to work.  So hopefully if anyone else has this problem they can get the answer. :)

northern_witch

#3
my solution is to patch response.lsp at line 71 replacing (nil? value) (cookie key "" (date-value)) with (nil? value) (cookie key "" 0) and continue using nil as documented



i think problem is about GMT and local time, so cookies expiration date is set to future by using date-value