Cookie question

Ken ken at hotmail.com
Tue Jun 4 17:02:37 CEST 2002


Do you set your cookie like this?
import Cookie
c = Cookie.SmartCookie()
c["UserID"] = string.rstrip(tusername)
c["Validated"] = "yes"
print c


And extract cookie like this?
if os.environ.has_key("HTTP_COOKIE"):
        strcookiex = os.environ["HTTP_COOKIE"]
        userid = extractCookieID(strcookiex,"UserID")
        validated = extractCookieID(strcookiex,"Validated")
--
def extractCookieID(strcookie,idx):
        strloc1 = string.find(strcookie,idx )
        strvalue = ""
        if strloc1 > -1:
                strvalue = strcookie[strloc1:]
                strloc1 = string.find(strcookie,"=")
                if strloc1 > 0:
                        strvalue = strvalue[strloc1 + 1:]
                strloc1 = string.find(strvalue,";")
                if strloc1 > 0:
                        strvalue = strvalue[0:strloc1]
        return strvalue


If I have many different cgi scripts checking UserID this way, are they all
refering to the same cookie?

If it is so, how come my other scripts can't read userid correctly? What did
I do wrong?

Also, where does the cookie get saved in my computer (using Win2000 Pro)? I
don't seem to find any cookie inside the Tempory Internet Files folder.

Thanks





More information about the Python-list mailing list