<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>

Hi;<br>
I'm trying to get this cookie code to work but it doesn't set the 
properties I want set (expires, path, comment, etc.). When I delete the 
cookie and run the script it duly creates a cookie. However, when I 
reload the page none of the morsels have values associated with them. I 
also do not see values when I look for them in my FireFox CookieCuller. I
 pretty much copied this code from an online tutorial so I'm wondering 
where the problem is.<br>
<br>
#!/usr/bin/env python<br>
<br>
import string<br>
import os<br>
import datetime, Cookie, random<br>
import time<br>
<br>
ourTime = str(time.time())<br>
cookie = Cookie.SimpleCookie()<br>
cookie['lastvisit'] = str(time.time())<br>
<br>
print cookie<br>
print 'Content-Type: text/html\n'<br>
<br>
print '<html><body>'<br>
print '<p>Server time is', time.asctime(time.localtime()), '</p>'<br>
<br>
# The returned cookie is available in the os.environ dictionary<br>
cookie_string = os.environ.get('HTTP_COOKIE')<br>
<br>
# The first time the page is run there will be no cookies<br>
if not cookie_string:<br>
    print '<p>First visit or cookies disabled</p>'<br>
    cookie = string.replace(ourTime, '.', '')<br>
    cookie = Cookie.SimpleCookie()<br>
    expiration = datetime.datetime.now() + datetime.timedelta(days=30)<br>
    cookie['lastvisit'] = str(time.time())<br>
    cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60<br>
    cookie['lastvisit']['path'] = '/var/www/html/my_site/'<br>
    cookie['lastvisit']['comment'] = 'holds the last user\'s visit date'<br>
    cookie['lastvisit']['domain'] = '.www.my_site.com'<br>
    cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60<br>
    cookie['lastvisit']['secure'] = ''<br>
    cookie['lastvisit']['version'] = 1<br>
<br>
else: # Run the page twice to retrieve the cookie<br>
   print '<p>The returned cookie string was "' + cookie_string + '"</p>'<br>
#   cookie = string.replace(string.split(str(cookie['lastvisit']), '=')[1], '.', '')[:-1]<br>
   # load() parses the cookie string<br>
   cookie.load(cookie_string)<br>
   # Use the value attribute of the cookie to get it<br>
   lastvisit = float(cookie['lastvisit'].value)<br>
   for morsel in cookie:<br>
     print '<p>', morsel, '=', cookie[morsel].value<br>
     print '<div style="margin:-1em auto auto 3em;">'<br>
     for key in cookie[morsel]:<br>
       print key, '=', cookie[morsel][key], '<br />'<br>
   print '</div></p>'<br>
<br>
print '</body></html>'<br>
<br>
TIA,<br>
Jack<br>
                                          </div></body>
</html>