#!/usr/local/bin/python import cgi, os, Cookie form = cgi.FieldStorage() newband = '' if (form.has_key('thebest')): newband = form['thebest'].value try: Cookie1 = Cookie.SmartCookie( os.environ.get("HTTP_COOKIE", "") ) band = Cookie1['favband'].value except KeyError: band = '' if newband != '': # setting a new band # make up a new cookie cookie = Cookie.SmartCookie() cookie['favband']=newband cookie['favband']['expires'] = 3600 # Time to keep, in seconds cookie['favband']['max-age'] = 3600 # Obsolete, Netscape may require it cookie['favband']['version'] = 1 #cookie['favband']['domain'] = 'whatever.com' # This isn't actually required cookie['favband']['path'] = '/' # This isn't actually required either print cookie print "Content-type: text/html\n\n" print "\n" if (band != '' and newband != '' and band != newband): print "Changing your favorite from %s to %s, I see...

\n" % (band, newband) print "Well, if you change your mind, click on a new one below

\n" elif (band != ''): print "Welcome back! I see your favorite is still %s

\n" % (band) print "Want to change it?

\n" elif (newband != ''): print "Setting your favorite to %s..

\n" % (newband) print "Well, if you change your mind, click on a new one below

\n"; else: print "Hi there. Pick your favorite band.

\n"; print """

Ramones
Beatles
GWAR
Backstreet Boys

"""