Server side cookie problems
rodmc
userprogoogle-139 at yahoo.co.uk
Wed Feb 6 12:27:53 EST 2008
Hi, I am trying to set a cookie on a client computer using the Cookie
module however all I get is the text being printed in the browser
window. Can anyone point me in the right direction so that the cookie
data is set without it appearing in the browser? A shortened version
of the code is below, in the full version there is also userID check,
this seems to work ok. I have removed that portion for the time being
as its the writing part that is the problem.
import sys, os, string, cgi, Cookie, urllib2
from types import ListType
cookie = Cookie.SimpleCookie()
cookieHdr = os.environ.get("HTTP_COOKIE", "")
cookie.load(cookieHdr)
def writetocookie(number):
#writes the ID of the database entry to a cookie
cookie["dataid"]=number
print "Content-Type: text/html"
print
print "Set-Cookie: dataid=",cookie["dataid"].value
writetocookie(1)
I presume this is not the correct way to write a cookie, the examples
I have found online don't seem to provide much more information.
Kind regards,
rod
More information about the Python-list
mailing list