The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
anyone know how to set a permanent cookie ?
Discuss anyone know how to set a permanent cookie ? in the Python Programming forum on Dev Shed. anyone know how to set a permanent cookie ? Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 13th, 2003, 08:55 PM
|
|
Contributing User
|
|
Join Date: Mar 2003
Posts: 325
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 11
|
|
|
anyone know how to set a permanent cookie ?
Hi
I've tried for a while now .. but can't find it anywhere when I search, but does anyone know how to set a cookie so that it's stay set between different browser sessions ?
Cheers,
Eli
|

October 14th, 2003, 02:24 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
I don't think any cookie can be "permanent", cookies by nature get deleted or eaten, go moldy etc  . I'm not sure but chouldn't you just give the cookie an unusually long best before date?
Mark.
__________________
programming language development: www.netytan.com – Hula
|

October 14th, 2003, 08:02 AM
|
 |
action=(isSleep())?sleep:code;
|
|
Join Date: Oct 2003
Location: Sydney->Indiana
Posts: 182
  
Time spent in forums: 15 h 8 m 29 sec
Reputation Power: 14
|
|
|
as said cookies can't be made to persist forever,
maxAge is what you want to set.
positive integers are how long the cookie persists in seconds, i think it's 32 bit so the biggest you could put in is 2^32 which is roughly 40,000 years NOTE! most browsers do not allow this, for some bizarre reason they max out at one year, going above this seems to invalidate the cookie and it dissappears as soon as the browser is closed, so use 60*60*24*365 = 31536000
set maxAge to -1 if you want it to persist until the browser closes
set to 0 and it will expire immeadiatly
|

October 14th, 2003, 08:22 AM
|
|
Junior Member
|
|
Join Date: Oct 2003
Location: Tucson AZ
Posts: 29
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
coookie expiration
What if you don't set an expiration or maxage?
What does python cookies default to?
I thought if this wasn't set a cookie would survive as long as the user allowed it to, (of course I haven't tested this with Python's cookie it's just my experience with cookies in general)
|

October 14th, 2003, 08:32 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Python's cookie module really just constructs and sends a cookie header to your web browser, if no expiration date is set then i'm guessing that no time or current time is used. I did look at the doc's on the Cookie module quickly but i didn't see anything on this subject. So, the cookie should expire imediatly or after the browser is closer.. just a guess though
Mark.
|

October 14th, 2003, 02:07 PM
|
|
Junior Member
|
|
Join Date: Oct 2003
Location: Tucson AZ
Posts: 29
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
I was able to find the answer to my own quesion on this page:
http://www.modpython.org/pipermail/...une/000692.html
There are three options that can be configured: CookieExpires, CookieName
and CookieTracking...
CookieExpires
This option sets an expiration time for the cookie generated by this module.
This time can be either a number of seconds or a string describing the
amount of time. If this option does not exist the cookie will expire when
the browser's session does....
so you were right Mark.
|

October 17th, 2003, 12:24 PM
|
|
Contributing User
|
|
Join Date: Mar 2003
Posts: 325
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 11
|
|
|
Ummm ... how do i set the cookie expires value ?
Do you have an example bit of code by chance?
Cheers
Eli
|

October 17th, 2003, 01:45 PM
|
|
Junior Member
|
|
Join Date: Oct 2003
Location: Tucson AZ
Posts: 29
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
cookie["name"]["expires"]=3600
where 3600 is the number of seconds you want it the cookie to last. (3600 would be for one hour).
|

October 17th, 2003, 09:00 PM
|
|
Contributing User
|
|
Join Date: Mar 2003
Posts: 325
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 11
|
|
|
ahhh.... Thank you for that
I don't know why it was so hard for me to find that when searching.
cheers,
Eli
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|