what's wrong with this cookie script

Steve Holden sholden at holdenweb.com
Wed Jan 16 08:35:55 EST 2002


"QdlatY" <qdlaty at ikom.pl> wrote in message
news:Xns91986F599497Fqdlatywielundhsorg at 153.19.253.204...
> Hello :-)
>
> I have something like this:
>
> #!python
> import cgi, Cookie, time
>
> form = cgi.FieldStorage()
> c = Cookie.SmartCookie()
>
> if form.has_key("register"):
> c["name"] = form["name"].value
> c["name"]["expires"] = 99999999#time.time() + 60
> c["email"] = form["email"].value
> c["email"]["expires"] = 99999999#time.time() + 60
> print c
>
> print "Content-type: text/html; charset=ISO-8859-2\n\n"
>
> if not c.has_key("name"):
> print """<FORM ACTION=cgi_dem.cgi METHOD=POST>
> Podaj swoje imie: <BR><INPUT NAME=name> <BR>
> Podaj swoj adres e-mail<BR><INPUT NAME=email><BR>
> <INPUT TYPE=HIDDEN NAME=register VALUE=true>
> <INPUT TYPE=SUBMIT></FORM>"""
> else:
> print "Proba odczytu danych z ciastka:<BR>"
> if c.has_key("name"): print "Twoje imie:", c["name"].value, "<BR>"
> if c.has_key("email"): print "Twoj e-mail:", c["email"].value
>
> I tried this on windows apache. Anyway, after i rerun IE, the cookie does
> not exists. What is wrong? Can anybody test this ?
>
This has worked for me, though since I wanted session cookies for this
application I commented it out after testing:

    def Cookie(self):
        cookie = Cookie.SimpleCookie()
        cookie["session"] = "%s:%d" % (self.session._id, id(self.session))
        cookie["session"]["path"] = "/"
        #cookie["session"]["expires"] = "31 Dec 2002" # Seems to make it
permanent
        return str(cookie)

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list