<div class="gmail_quote">On Wed, Dec 30, 2009 at 11:54 AM, Carsten Haese <span dir="ltr"><<a href="mailto:carsten.haese@gmail.com">carsten.haese@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">Victor Subervi wrote:<br>
> Here again is my code:<br>
><br>
> #! /usr/bin/python<br>
><br>
> import string<br>
> import cgitb; cgitb.enable()<br>
> import MySQLdb<br>
> import cgi<br>
> import sys,os<br>
> sys.path.append(os.getcwd())<br>
> from login import login<br>
> import datetime, Cookie, random<br>
> from particulars import title<br>
> from templateFrame import top, bottom<br>
> from particulars import myCookie<br>
> import time<br>
> import fpformat<br>
> from sets import Set<br>
> from particulars import ourOptions<br>
><br>
> def cart():<br>
> print '''Content-Type: text/html\r\n<br>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br>
> <html><br>
> '''<br>
> cookie = os.environ.has_key('HTTP_COOKIE')<br>
> if not cookie:<br>
> cookie = Cookie.SimpleCookie()<br>
> cExpires, cPath, cComment, cDomain, cMaxAge, cVersion = myCookie()<br>
> cookie['lastvisit'] = str(time.time())<br>
> cookie['lastvisit']['expires'] = cExpires<br>
> cookie['lastvisit']['path'] = cPath<br>
> cookie['lastvisit']['comment'] = cComment<br>
> cookie['lastvisit']['domain'] = cDomain<br>
> cookie['lastvisit']['max-age'] = cMaxAge<br>
> cookie['lastvisit']['version'] = cVersion<br>
> cookie['mycookie'] = 'mycookie'<br>
> cookieFlag = 'new'<br>
> else:<br>
> cookie = Cookie.SimpleCookie(cookie)<br>
> cookieFlag = 'old'<br>
> # Don't know what to do with this. It's for when client won't accept<br>
> cookies<br>
> # sessionDir = os.environ['DOCUMENT_ROOT'] + '/tmp/.session'<br>
> # session = shelve.open(sessionDir + '/sess_' + sid, writeback=True)<br>
> # session['lastvisit'] = repr(time.time())<br>
> # session.close()<br>
> print cookieFlag<br>
> cookie.load(cookie)<br>
> print cookie<br>
> ...<br>
><br>
> Please advise.<br>
<br>
</div></div>Pardon me for not being able to read your mind. The code you're now<br>
posting is significantly more code than your first post included. The<br>
line that I had determined to be missing is in fact not missing, you<br>
just didn't bother to post your actual code.<br></blockquote><div><br>As my British father would have said, you're a gentleman and a scholar...<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Now that you've posted your actual code, I can see that the actual<br>
problem is that the line is in the wrong place.<br>
<br>
The line in question is <<print cookie>>, and it's responsible for<br>
printing a "Set-Cookie" *HEADER*, which is a fact that at least one of<br>
the tutorials you pointed out has mentioned. You're printing it where it<br>
doesn't belong, in the middle of your HTML output. You need to<br>
reorganize your print statements such that the Set-Cookie header is<br>
printed in the header of your script's output.<br></blockquote><div><br>I've revised the code thus:<br><br> cookie = os.environ.has_key('HTTP_COOKIE')<br> if not cookie:<br> cookie = Cookie.SimpleCookie()<br>
cExpires, cPath, cComment, cDomain, cMaxAge, cVersion = myCookie()<br> cookie['lastvisit'] = str(time.time())<br> cookie['lastvisit']['expires'] = cExpires<br> cookie['lastvisit']['path'] = cPath<br>
cookie['lastvisit']['comment'] = cComment<br> cookie['lastvisit']['domain'] = cDomain<br> cookie['lastvisit']['max-age'] = cMaxAge<br> cookie['lastvisit']['version'] = cVersion<br>
print cookie<br> cookieFlag = 'new'<br> <br>Unfortunately, this still prints "new" for the cookieFlag no matter how many times I refresh. Please advise.<br>TIA,<br>beno<br></div></div>