At 10:20 PM 12/7/01 +0000, Costas Malamas wrote:
>Hello again,
>
>I tried the solution on the Wiki, but no luck. I am setting a cookie with
>session.response().addCookie(c) in writeHTML, where c has the properties
>Geoff had in his example (+10 yrs expiration), but the cookie does not
>persist across browser instances. Initially, I thought this was because
>of IE6's cookie blocking behavior, but I have reproduced it with Mozilla 0.96.
>
>Any ideas anybody? I am clueless...
>
>Thanks in advance,
>
>Costas
Well, all I can say is it works for me, on Windows NT with both IE 5.5 and
Netscape 4.7. I can completely exit from the browser and when I re-enter
the browser, the cookies are still there.
Try the sample servlet that I attached and see if it works.
--
- Geoff Talvola
[EMAIL PROTECTED]
from WebKit.Page import Page
from WebKit.Cookie import Cookie
import time
class PermanentCookie(Page):
def actions(self):
return ['addCookie', 'deleteCookie']
def addCookie(self):
req = self.request()
key = req.field('key')
value = req.field('value')
self.setPermanentCookie(key, value)
wr = self.writeln
wr('Your cookie has been added.<br>')
wr('<a href=PermanentCookie>Return to PermanentCookie page</a>')
def deleteCookie(self):
req = self.request()
key = req.field('key')
self.deletePermanentCookie(key)
wr = self.writeln
wr('Your cookie has been deleted.<br>')
wr('<a href=PermanentCookie>Return to PermanentCookie page</a>')
def writeContent(self):
wr = self.writeln
req = self.request()
cookies = req.cookies().items()
wr('cookies:<br>')
wr('<table>')
for key, value in cookies:
wr('<tr><td>%s</td><td>%s</td></tr>' % (self.htmlEncode(key),
self.htmlEncode(value)))
wr('</table>')
wr('<form>')
wr('Add cookie:<br>')
wr('<table>')
wr('<tr><td>Key:</td><td><input type=text name=key></td></tr>')
wr('<tr><td>Value:</td><td><input type=text name=value></td></tr>')
wr('</table>')
wr('<input name=_action_addCookie type=submit value="Add Cookie">')
wr('</form>')
wr('<form>')
wr('Delete cookie:<br>')
wr('<table>')
wr('<tr><td>Key:</td><td><input type=text name=key></td></tr>')
wr('</table>')
wr('<input name=_action_deleteCookie type=submit value="Delete Cookie">')
wr('</form>')
def setPermanentCookie(self, key, value):
cookie = Cookie(key, value)
t = time.gmtime(time.time())
t = (t[0] + 10,) + t[1:]
t = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", t)
cookie.setExpires(t)
self.response().addCookie(cookie)
def deletePermanentCookie(self, key):
cookie = Cookie(key, '')
t = time.gmtime(time.time())
t = (t[0] - 10,) + t[1:]
t = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", t)
cookie.setExpires(t)
self.response().addCookie(cookie)