Get cookie expiry time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mymatebob@googlemail.com

    #1

    Get cookie expiry time

    Hi,

    I am using cookies to keep track if a user is logged into my system,
    and would like to display the time that the user has left logged in.
    One solution is to display the time left until the cookie expires.

    Does anyone know how to retrieve the expiry time of a particular
    cookie?

    TIA

    Jeff

  • mymatebob@googlemail.com

    #2
    Re: Get cookie expiry time

    If the above is not possible, then I suppose one solution is to store
    the expiry time in an additional cookie.

    Comment

    • Andy Jeffries

      #3
      Re: Get cookie expiry time

      On Tue, 02 May 2006 03:05:15 -0700, mymatebob wrote:[color=blue]
      > If the above is not possible, then I suppose one solution is to store the
      > expiry time in an additional cookie.[/color]

      Or re-set the cookie for a known expiry time on every page view (say ten
      minutes and 20 seconds) then countdown in Javascript for ten minutes (the
      extra 20 seconds is grace period and to allow for the page to
      download/Javascript to start).

      Cheers,


      Andy

      --
      Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
      http://www.gphpedit.org | PHP editor for Gnome 2
      http://www.andyjeffries.co.uk | Personal site and photos

      Comment

      • mymatebob@googlemail.com

        #4
        Re: Get cookie expiry time

        Sounds a bit overly complicated! But an interesting solution.

        It seems strange that there's no method in PHP for obtaining the cookie
        expiry time. Ah well. In the mean time I have stuck with the "storing
        expiry time in another cookie" method. Suppose I could add a Java
        Script function to check the values every second to produce a real time
        "time left until log out" counter.

        Many thanks for the response!

        Jeff

        Comment

        • Andy Jeffries

          #5
          Re: Get cookie expiry time

          On Wed, 03 May 2006 02:32:36 -0700, mymatebob@googl email.com wrote:[color=blue]
          > Sounds a bit overly complicated! But an interesting solution.[/color]

          Not that complex though, it's only a matter of iterating through $_COOKIE
          and resetting each one with a known expiry time (strtotime("+10 minutes
          and 20 seconds")). You could do this in a single file and automatically
          use it on every page using php_value auto_prepend_fi le in the Apache
          virtualhost.
          [color=blue]
          > It seems strange that there's no method in PHP for obtaining the cookie
          > expiry time.[/color]

          It's not really strange, if you examine the HTTP spec (or watch HTTP
          headers using Firefox's Live HTTP Headers) you'll find the browser doesn't
          send back the expiry date to the server, only the name and value.
          Therefore it's not strange that PHP can't obtain the information, it's
          never told (and it can't just remember what it set because it could have
          been changed with Javascript or by editing the cookies.txt file).
          [color=blue]
          > Ah well. In the mean time I have stuck with the "storing
          > expiry time in another cookie" method. Suppose I could add a Java Script
          > function to check the values every second to produce a real time "time
          > left until log out" counter.
          >
          > Many thanks for the response![/color]

          You're welcome.

          Cheers,


          Andy

          --
          Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
          http://www.gphpedit.org | PHP editor for Gnome 2
          http://www.andyjeffries.co.uk | Personal site and photos

          Comment

          • mymatebob@googlemail.com

            #6
            Re: Get cookie expiry time

            Ah! That IS a good solution. I was thinking of setting a default expiry
            of 4 hours, but with your solution, the cookies keep in date as long as
            the user is actively using the website - much more user friendly.

            Thanks for explaining the missing functions I was looking for in PHP. I
            saw the cookie expiry date in the "View Cookies" Firefox extension and
            just assumed the value would be readily available somehow.

            Cheers

            Jeff

            Comment

            • Andy Jeffries

              #7
              Re: Get cookie expiry time

              On Thu, 04 May 2006 00:12:32 -0700, mymatebob@googl email.com wrote:[color=blue]
              > Ah! That IS a good solution. I was thinking of setting a default expiry of
              > 4 hours, but with your solution, the cookies keep in date as long as the
              > user is actively using the website - much more user friendly.
              >
              > Thanks for explaining the missing functions I was looking for in PHP. I
              > saw the cookie expiry date in the "View Cookies" Firefox extension and
              > just assumed the value would be readily available somehow.[/color]

              You're more than welcome mate, best of luck with your project.

              Cheers,


              Andy


              --
              Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
              http://www.gphpedit.org | PHP editor for Gnome 2
              http://www.andyjeffries.co.uk | Personal site and photos

              Comment

              Working...