Cookie gets changed when hit comes from a referrer

Piet van Oostrum piet at vanoostrum.org
Wed Oct 9 14:36:56 EDT 2013


Νίκος Αλεξόπουλος <nikos.gr33k at gmail.com> writes:

>
> # initialize cookie and retrieve cookie from clients browser
> cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )
>
> if cookie.get('ID') is not None:
> 	cookieID = cookie['ID'].value
> else:
> 	cookieID = random.randrange(0, 9999)
> 	cookie['ID'] = cookieID
> 	cookie['ID']['domain'] = ".superhost.gr"
> 	cookie['ID']['path'] = '/'
> 	cookie["ID"]["expires"] = 60*60*24*365		# this cookie will expire in a year
>
As Ian already has told you (but apparently you didn't pay attention to), your expires is wrong. So if your cookies disappear you should get this right first.

from datetime import datetime, timedelta
expiretime = datetime.utcnow() + timedelta(days=365)

cookie["ID"]["expires"] = expiretime.strftime("%a, %d %b %Y %H:%M:%S GMT")
-- 
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]



More information about the Python-list mailing list