Can't get cookies working

For the Compleat Fan
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Can't get cookies working

Post by cormullion »

I can't get cookies working. The code I have is this:

Code: Select all

(load "...cgi.lsp")
(CGI:set-cookie "password" "secret" "asite.com" "/somedir")

(print "Content-type: text/html\n\r\n\r")
If I swap these two lines round, I can see the password/secret/asite stuff at the top of the page, but when they're the right way round no cookies are sent.

Any ideas for getting it working?

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Post by rickyboy »

What about ending the line with \r\n\r\n instead of \n\r\n\r? Does that make a difference? (I'm not trying to be cute, I just am not in a position to test that.)
(λx. x x) (λx. x x)

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Post by rickyboy »

Also, is it possible to load the file ...cgi.lsp? I mean three dots, then cgi.lsp? While it is possible to name a file this way, it might not be what you meant.
(λx. x x) (λx. x x)

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Yes, that was just shorthand - I didn't put the full path of cgi.lsp in, since I've got it stored somewhere else. But I think it's working OK - the rest of the CGI stuff is working fine... Just can't get any cookies to appear.

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Post by rickyboy »

cormullion wrote:Yes, that was just shorthand - I didn't put the full path of cgi.lsp in, since I've got it stored somewhere else.
Oh, sorry about that. Well, I guess that leaves me tapped. :-(
(λx. x x) (λx. x x)

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Here is a small working cookie example:

http://newlisp.org/code/cookie.cgi

The first time you go to the page it will say "No cookie found", the second time it will show the cookie.

here the source:

Code: Select all

#!/usr/bin/newlisp

(load "cgi.lsp")

(CGI:set-cookie "key" (uuid) "newlisp.org" "/code")

(print "Content-type: text/html\r\n\r\n")

(if (CGI:get-cookie "key")
	(println "<h2>Cookie found:" (CGI:get-cookie "key") "<h2>")
	(println "<h2>No cookie found</h2>"))

(exit)
Lutz

ps: for an example using cookie expiration time see the calendar application on the http://newlisp.org/index.cgi?Code_Contributions page

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

As I feared, it's not the cookie code, but something else. Your example works fine, but when copied to another place produces the error:

Code: Select all

list expected in function lookup : cookies called from user defined function CGI:get-cookie

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

There was a problem in cgi.lsp v.2.1 and earlier when '=' signs where present in the cookie key or value string. This has been fixed in cgi.lsp version 2.2 distributed since 9.2.1.

What version of cgi.lsp are you using?

Lutz

ps: 'cookies' is a variable local to the CGI name space as CGI:cookies and set to '() if no cookies are present.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Ah - your file doesn't work when copied to the server - says 'no cookie found' each time. So presumably there's something on the server that's preventing it working...

Edit: i now suspect that the expiry date is compulsory. Will investigate.

Edit: I think its working. Domain name had two dots perhaps.

Locked