Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

print "welcome!! "

print cookies

print ""

else:

print "Content-type:text/html"

print "Set-Cookie:"+fields['userid']+"="+fields['pswd']+";HttpOnly; Path=/"

print

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions