Question: CGI script cookie problems I have my code here: #----------------------------------------------- if environ.has_key('HTTP_COOKIE'): cookies = {} for cookie in environ['HTTP_COOKIE'].split(';'): (key, value) = cookie.split(=); cookies[key] =
CGI script cookie problems
I have my code here:
#-----------------------------------------------
if environ.has_key('HTTP_COOKIE'):
cookies = {}
for cookie in environ['HTTP_COOKIE'].split(';'):
(key, value) = cookie.split("=");
cookies[key] = value
try:
str = cookies[fields['userid']]
print "Content-type:text/html"
print "
"print "welcome back! {0}".format(str)
print ""
except KeyError:
print "Content-type:text/html"
print "Set-Cookie:"+fields['userid']+"="+fields['pswd']+";HttpOnly; Path=/"
print "
"print "welcome!! "
print cookies
print ""
else:
print "Content-type:text/html"
print "Set-Cookie:"+fields['userid']+"="+fields['pswd']+";HttpOnly; Path=/"
print "
"print "welcome"
print ""
#-----------------------------------------------
this CGI script is based on python, my prof required us not to use cgi or html packages
A user's information is stored in cookies when he logs in. when previously logged in users logs in, they are welcomed back. when new users login, their information will be stored in cookies.
When I try to get a userid and pswd pair into cookie, it works fine.
however for another userid and pswd, it keeps going into KeyError, and the output for the previously logged user is not welcomed back
Is the cookies are not updated? if so, how should I update?
cgi and html packages cannot be used!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
