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!
thanks liquedus but i want to link this script to call out the username from the users table. So for each person that is on the site it will take their name from the user database.
Inter i see what you mean, just not sure how to go about it.
<?php
// Stuff For Users Online (its here so users online information is recorded on every page)
$timeout = 5*60; //minutes (* 60) until user 'times' out
$date = time(); //now
$time_minus_timeout = $date - $timeout; //how many minutes from 'now' they timeout
//find total people online now
$totalonline = rows_query("SELECT userid FROM online WHERE lastonline > $time_minus_timeout");
//total online ever
$data = fetch_query("SELECT value FROM misc WHERE name = 'mostonline'");
$mostonline = $data['value'];
if ($totalonline > $mostonline) {
$totalonline_date = time();
$query = reg_query("UPDATE misc SET value = '$totalonline_date' WHERE name = 'mostonline_date'");
$query = reg_query("UPDATE misc SET value = '$totalonline' WHERE name = 'mostonline'");
}
$new = 1;
//if the user is logged in.. or else not logged in
if ($_SESSION['ib_userid']) {
$query = reg_query("SELECT userid, ip FROM online WHERE lastonline > $time_minus_timeout");
while ($data = fetchonly_query($query)) {
if ($_SESSION['ib_userid'] == $data['userid']) {
$new = 0;
break;
}
}
//insert him into the table
if ($new == 1) $query = reg_query("INSERT INTO online (userid, name, lastonline, ip) VALUES ('$_SESSION[ib_userid]', '$_SESSION[ib_username]', '$date', '$_SERVER[REMOTE_ADDR]')");
//the user might have been considered a guest so delete his guest <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> just in case
$query = reg_query("DELETE FROM online WHERE ip = '$_SERVER[REMOTE_ADDR]' AND userid = '-1'");
} else {
$query = reg_query("SELECT ip FROM online WHERE lastonline > $time_minus_timeout");
while ($data = fetchonly_query($query)) {
if ($_SERVER['REMOTE_ADDR'] == $data['ip']) {
$new = 0;
break;
}
}
//insert him into the table
if ($new == 1) $query = reg_query("INSERT INTO online (userid, name, lastonline, ip) VALUES ('-1', 'Guest', '$date', '$_SERVER[REMOTE_ADDR]')");
}
$guests_online = rows_query("SELECT userid FROM online WHERE userid = '-1'");
//create users online string
$query = reg_query("SELECT name FROM online WHERE userid != '-1'");
while ($data = fetchonly_query($query)) {
$i++;
if ($i != $totalonline) {
$online_string .= $data['name'].", ";
$onlin_list .= $data['name']."<br>\n";
} else {
$online_string .= $data['name'];
$online_list .= $data['name'];
}
}
$members_online = rows_query("SELECT name FROM online WHERE userid != '-1'");
// Delete all the old ones
$query = reg_query("DELETE FROM online WHERE lastonline < $time_minus_timeout");
?>