PDA

View Full Version : Display users online


mouse
08-16-2002, 12:41 AM
I'd like a page where I can check whether any users are online, ip's etc. Obviously not for public consumption.

How can I do this?

IKinsler
08-18-2002, 09:42 PM
I've always been meaning to try, but never have, it might help if you downloaded a version of, say, phpBB, and looked at the code for their "Who's Online?" script, and then made your own.

mouse
08-18-2002, 10:15 PM
I've got Invision board but dunno where to start looking tbh :o

I think the procedure may be to log the details in a database with some kind of time stamp then select those who've visited in the past x minutes.

I've not worked with time before, I'll have to go look that up...

_Spud_
08-19-2002, 04:49 PM
I can tell you how to print how many users are online, but this involves a MYSQL db, and does not give IP info. But it can be a starting block to help you.

1 Create the MySQL Table

CREATE TABLE useronline (
timestamp int(15) DEFAULT '0' NOT NULL,
ip varchar(40) NOT NULL,
file varchar(100) NOT NULL,
PRIMARY KEY (timestamp),
KEY ip (ip),
KEY file (file)
);

And now the best bit, the php code it’s self.


<?php

$server = "xxx";
$db_user = "xxx";
$db_pass = "xxx";
$database = "xxx";
$timeoutseconds = 300;

$timestamp = time();
$timeout = $timestamp-$timeoutseconds;

mysql_connect($server, $db_user, $db_pass);
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')");
if(!($insert)) {
print "Useronline Insert Failed > ";
}
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout");
if(!($delete)) {
print "Useronline Delete Failed > ";
}
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'");
if(!($result)) {
print "Useronline Select Error > ";
}
$user = mysql_num_rows($result);


mysql_close();
if($user == 1) {
print("<b>$user</b> user online\n");
} else {
print("<b>$user</b> users online\n");
}

?>


Hope this helps