Problems deleting cookie with newLISP and Dragonfly

A web framework in newLISP

Problems deleting cookie with newLISP and Dragonfly

Postby Jeremy Reimer » Tue Nov 09, 2010 11:28 pm

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.
Jeremy Reimer
 
Posts: 19
Joined: Thu May 13, 2010 5:36 pm

Re: Problems deleting cookie with newLISP and Dragonfly

Postby cormullion » Wed Nov 10, 2010 7:49 pm

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 ... :)
cormullion
 
Posts: 2037
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W

Re: Problems deleting cookie with newLISP and Dragonfly

Postby Jeremy Reimer » Wed Nov 10, 2010 10:26 pm

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. :)
Jeremy Reimer
 
Posts: 19
Joined: Thu May 13, 2010 5:36 pm

Re: Problems deleting cookie with newLISP and Dragonfly

Postby northern_witch » Sat Nov 20, 2010 7:43 pm

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
northern_witch
 
Posts: 2
Joined: Fri Mar 05, 2010 10:16 pm


Return to Dragonfly

Who is online

Users browsing this forum: No registered users and 1 guest