Can't get cookies working

Started by cormullion, October 05, 2007, 07:22:33 AM

Previous topic - Next topic

cormullion

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


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

(print "Content-type: text/htmlnrnr")


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

#1
What about ending the line with rnrn instead of nrnr?  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

#2
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

#3
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

#4
Quote from: "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.

Oh, sorry about that.  Well, I guess that leaves me tapped.  :-(
(λx. x x) (λx. x x)

Lutz

#5
Here is a small working cookie example:



http://newlisp.org/code/cookie.cgi">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:


#!/usr/bin/newlisp

(load "cgi.lsp")

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

(print "Content-type: text/htmlrnrn")

(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">http://newlisp.org/index.cgi?Code_Contributions page

cormullion

#6
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:


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

Lutz

#7
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

#8
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.