Page 1 of 1

Problems deleting cookie with newLISP and Dragonfly

Posted: Tue Nov 09, 2010 11:28 pm
by 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:

Code: Select all

	(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":

Code: Select all

 (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.

Re: Problems deleting cookie with newLISP and Dragonfly

Posted: Wed Nov 10, 2010 7:49 pm
by cormullion
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 ... :)

Re: Problems deleting cookie with newLISP and Dragonfly

Posted: Wed Nov 10, 2010 10:26 pm
by Jeremy Reimer
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

Code: Select all

	(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)

Code: Select all

(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. :)

Re: Problems deleting cookie with newLISP and Dragonfly

Posted: Sat Nov 20, 2010 7:43 pm
by northern_witch
my solution is to patch response.lsp at line 71 replacing

Code: Select all

(nil? value) (cookie key "" (date-value))
with

Code: Select all

(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