Help: adding last login date to SQL database for who's online.

i hope you guys can help me out, i’m a relative PHP newbie, and even less experienced with SQL so please bare with me.

i have a basic members script running which allows a user to register and then as a member log in to access certain pages, then logout.
what i want to do is have a info box listing who’s online. eg: “who’s online: bert, ernie, kermit”

i found this tutorial online though the author doesn’t seem to provide the SQL tables to use it.
which uses this code:
[php]First we’re gonna check if the user is online.

<?PHP //Get users time from the users table $getuser=mysql_query("SELECT * FROM users") or die (mysql_error()); while($users_row=mysql_fetch_array($getuser)){ $user=$users_row['user'];//Get the users name from database $users_time=$users_row['last_active'];//Get the users time from database $time = time() - 100;//Current time minus 100ms if($users_time >= $time){//Check if users time is greater than or equal to $time $user_online="Online"; $online .="$user $user_online";//Put users name and online status in a variable } } ?>

Insert this into your html body where you want the users to be display.

<?PHP echo $online; ?>

Insert this into every page.

<?PHP session_start();//Start the session. Only use if you have not started the session. $user=$_SESSION['user'];//Get session user $time=time();//Get current time //Update the current users time mysql_query("UPDATE users Set last_active='$time' WHERE user='$user'") or die (mysql_error()); ?>

Only show the users online.

<?PHP $time=time();//Get current time $time=$time - 100;//Current time minus 100ms //Select only users where last active is greater than or equal to $time $online_user=mysql_query("SELECT * FROM users WHERE last_active >='$time'") or die (mysql_error()); while($users_row=mysql_fetch_array($online_user)){ $user=$users_row['user'];//Get the users name from database $online .=$user; } ?>

Insert this into you html body where you want to display all users online

<?PHP echo $online; ?>[/php]

here’s the SQL database i’m currently using for my member script:

CREATE TABLE IF NOT EXISTS `members` ( `id` int(11) NOT NULL auto_increment, `username` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `ip` varchar(255) NOT NULL, `date` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 ;

what would i have to add to the database table to achieve a last login?

please excuse my ignorance and thanks in advance,
holly

Sponsor our Newsletter | Privacy Policy | Terms of Service