SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Dec 1999
    Location
    Highlands Ranch, CO
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I display the time that a cookie expires?

    I am setting cookies with an expiration in 1 week.

    Is there a way to extract 'how much time is left' before the cookie expires?

    I want to let the user know "Your cookie will expire in XX hours"

    TIA

  2. #2
    SitePoint Zealot
    Join Date
    Dec 1999
    Location
    Highlands Ranch, CO
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nobody knows? Or is it just not possible?

    PHP/Cookie experts, please help!

  3. #3
    SitePoint Member
    Join Date
    Dec 2002
    Location
    San Jose, CA
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I don't know anything about PHP cookies and if they are any different from JavaScript (JS) cookies (im pretty new to PHP) But I do know that when you set a JS cookie, you have to set an expiration date/time. You usually this is done by finding the current time then adding X seconds to it. (JS is stupid and does everything in seconds since 198X or somthing stupid like that) To find out how much more time they have, you can simply store the time at which the cookie was created, and how long the cookie lasts. With these two pieces of imformation you can calculate how long untill the cookie expires.
    -Hobadee

  4. #4
    SitePoint Zealot
    Join Date
    Dec 1999
    Location
    Highlands Ranch, CO
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hob,

    Thanks for the info. I may end up trying that. I was just hoping that there was a way to view the time of the expiration from expiration itself.

    Also, does anyone know how secure cookies are?

    I mean - say I give a 2 week trial to my site. I use a 2 week cookie to determine when their time expires. When the cookie expires, they are no longer granted access. This is opposed to a log-in script.

    How easy is it to 'alter' a cookie to allow more time before expiration? Does anyone see security faults to this?

  5. #5
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would recommend that you set a cookie with a unique user id in when you start the 2 week trial. When the user visits, it cross checks the user id with a list of allowed users. If the user is not in the list, or the trial has expired, access is not granted. Simple.

    Matt.

  6. #6
    SitePoint Zealot
    Join Date
    Dec 1999
    Location
    Highlands Ranch, CO
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hob - I ended up sending the cookie's value as "time()".

    Then I just subtract that value from the current value of "time()" when the user hits the page.

    Works great, thanks.

    Mincer - thanks, I will look into that...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •