about last login date in cookies

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perhapscwk
    New Member
    • Sep 2007
    • 123

    about last login date in cookies

    How to update stored cookies value without change the cookies expired date?

    when I login on monday, I have use "remember me for 1 week" to store my login in cookies with my last login date(monday). so next day(tuesday), when I access the site, i don';t need to login again and it show my last login date(monday).

    However, if I access the page in Fri, it still show me my last login on Monday.
    How to modify the cookies to show correct last access date?
  • chathura86
    New Member
    • May 2007
    • 227

    #2
    Please post the code you are using to set the cookie, it may be helpful.

    Comment

    • perhapscwk
      New Member
      • Sep 2007
      • 123

      #3
      Code:
       $info = base64_encode("$userid|$username|$password|$ipaddress|$lastlogin_date|$lastlogin_time");
                       if (isset($remember)){
                           setcookie("user","$info",time()+1209600); 
                       }
      thanks.

      Comment

      • chathura86
        New Member
        • May 2007
        • 227

        #4
        well on the next login you have to update the $lastlogin_date and $lastlogin_time

        by the way it is not a good idea to store the password in a cookie

        Regards

        Comment

        • perhapscwk
          New Member
          • Sep 2007
          • 123

          #5
          if update the last login date and time, the cookies expired period will update
          as well, how to update cookies without chnage it's expired time?

          Comment

          • chathura86
            New Member
            • May 2007
            • 227

            #6
            you have to calculate and subtract the time and reset cookie with the new time
            because there is no way to get the expire date from the cookie (as far as i know)

            so the easiest method is store the last login date in db, or you can set the expire date also in the cookie and use that to set the expire date

            eg
            Code:
            $expire = time()+1209600;
            
             $info = base64_encode("$userid|$username|$password|$ipaddress|$lastlogin_date|$lastlogin_time|$expire");
            if (isset($remember)){
                   setcookie("user","$info",$expire); 
            }
            so the next time he logs in you can get the expire date and set the cookie with the $expire time so the expire date will not change

            Regards

            Comment

            Working...