#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    325
    Rep Power
    12

    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
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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

  4. #3
  5. action=(isSleep())?sleep:code;
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Sydney->Indiana
    Posts
    182
    Rep Power
    15
    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
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Tucson AZ
    Posts
    29
    Rep 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)
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula

  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Tucson AZ
    Posts
    29
    Rep Power
    0
    I was able to find the answer to my own quesion on this page:
    http://www.modpython.org/pipermail/m...ne/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.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    325
    Rep Power
    12
    Ummm ... how do i set the cookie expires value ?
    Do you have an example bit of code by chance?

    Cheers
    Eli
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Tucson AZ
    Posts
    29
    Rep 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).
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    325
    Rep Power
    12
    ahhh.... Thank you for that

    I don't know why it was so hard for me to find that when searching.

    cheers,
    Eli

IMN logo majestic logo threadwatch logo seochat tools logo