Gubbins Posted October 19, 2008 Share Posted October 19, 2008 I have tried various ways to find out when the people on my web site last logged in! I cant seem to get it right! I would like to add it to there profiles so we can all see who is active and so on! I know i will need to add a table into the database to for the info to be stored! Can anyone help please? Kind regards Gubbins Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/ Share on other sites More sharing options...
Andy17 Posted October 19, 2008 Share Posted October 19, 2008 You could use the date() function when the user logs in to get the time and then insert it into your user table. Something like this: <?php // Login check and use of the date() function here $sql = "INSERT INTO users WHERE username = '$username' (lastlogin) VALUES ('$date')"; $result = mysql_query($sql) or die(mysql_error()); if ($result) { $row = mysql_fetch_array($result)) echo $row['lastlogin']; } ?> Try something like that. Never actually did it before so I'm not 100% if the query is structured correctly. Give it a show and good luck! Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/#findComment-669313 Share on other sites More sharing options...
Gubbins Posted October 19, 2008 Author Share Posted October 19, 2008 Thank you for replying so fast! Do i add that into the profile.php file? Also I dont use user and username but i can easily change that! Do i need an entry into the players section of the database and if so would the name be lastlogin? i.e. Field, lastlogin Type, date Default, 0000-00-00 Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/#findComment-669329 Share on other sites More sharing options...
Andy-H Posted October 19, 2008 Share Posted October 19, 2008 Add a field last_active (varchar 255) in the players table, and add this to your connections/requires.php script... $act = gmdate('M, dS, Y, h:i A'); mysql_query("UPDATE players SET last_active = '$act' WHERE playername = '$player' LIMIT 1")or trigger_error(mysql_error()); Then echo it out in a field on profiles... //Edit // Edited date format. Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/#findComment-669366 Share on other sites More sharing options...
Andy17 Posted October 19, 2008 Share Posted October 19, 2008 Wow, can't believe I forgot to use UPDATE instead of INSERT INTO. Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/#findComment-669378 Share on other sites More sharing options...
Andy-H Posted October 19, 2008 Share Posted October 19, 2008 lmao Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/#findComment-669379 Share on other sites More sharing options...
Gubbins Posted October 19, 2008 Author Share Posted October 19, 2008 Thank you both for all your help! I have added the entry into the database Andy H i am a little unsure what you mean by echo it out! i would like to see the text i have to add if possible as you can tell i am a novice at this! lol Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/#findComment-669408 Share on other sites More sharing options...
Gubbins Posted October 19, 2008 Author Share Posted October 19, 2008 I got it working thanks again for all your help Please close the thread! Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/#findComment-669451 Share on other sites More sharing options...
Andy-H Posted October 20, 2008 Share Posted October 20, 2008 I know Trevor, it's Andy off msn, lmao... Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/#findComment-669833 Share on other sites More sharing options...
Andy17 Posted October 20, 2008 Share Posted October 20, 2008 I got it working thanks again for all your help Please close the thread! Just hit the "Topic solved" (or something like that) at the bottom of the page to the left to mark it as solved instead. Link to comment https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/#findComment-670198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.