By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

about last login date in cookies

100+
P: 123
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?
Apr 13 '10 #1
Share this Question
Share on Google+
5 Replies


chathura86
100+
P: 227
Please post the code you are using to set the cookie, it may be helpful.
Apr 13 '10 #2

100+
P: 123
Expand|Select|Wrap|Line Numbers
  1.  $info = base64_encode("$userid|$username|$password|$ipaddress|$lastlogin_date|$lastlogin_time");
  2.                  if (isset($remember)){
  3.                      setcookie("user","$info",time()+1209600); 
  4.                  }
thanks.
Apr 13 '10 #3

chathura86
100+
P: 227
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
Apr 13 '10 #4

100+
P: 123
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?
Apr 14 '10 #5

chathura86
100+
P: 227
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
Expand|Select|Wrap|Line Numbers
  1. $expire = time()+1209600;
  2.  
  3.  $info = base64_encode("$userid|$username|$password|$ipaddress|$lastlogin_date|$lastlogin_time|$expire");
  4. if (isset($remember)){
  5.        setcookie("user","$info",$expire); 
  6. }
  7.  
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
Apr 14 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.