simple question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

simple question

Post 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!
santosj
Forum Contributor
Posts: 157
Joined: Sat Apr 29, 2006 7:06 pm

Post 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']) ."'");
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

Thanks! i will check it right away!
Post Reply