Page 1 of 1

simple question

Posted: Sun May 21, 2006 12:37 pm
by Milan
I want to add a timestamp for the "last seen" field in the user database but i have to read a cookie to get a user name.

How can i read the username from the cookie and add a time stamp for the username in the cookie?
Table name is users and and field name is "lastseen"

thanks a lot!

Posted: Sun May 21, 2006 3:43 pm
by santosj
I'm sorry. This isn't very secure. I also use time() for the timestamp because I like the integer for allowing me to display the time how I want using the date() function.

Code: Select all

mysql_query("UPDATE users 
SET lastseen=". time() ." 
WHERE username='". mysql_escape_string($_COOKIE['username']) ."'");
Or if the mysql type is of TIMESTAMP and you can't use time(), then do this instead.

Code: Select all

mysql_query("UPDATE users 
SET lastseen=CURRENT_TIMESTAMP() 
WHERE username='". mysql_escape_string($_COOKIE['username']) ."'");

Posted: Sun May 21, 2006 5:15 pm
by Milan
Thanks! i will check it right away!