PDA

View Full Version : You see above where it says (users browsing this forum)........


Silver Sun
10-13-2002, 07:56 PM
does anyone here know how to do that?

Basically, i need a list of people currently on a webpage that automatically updates. Like the (users browsing this forum) thingy.


Thanks in advance:thumbsup:

Nightfire
10-14-2002, 11:32 PM
I can give you an example of a who's online script, shows guests and members. It'll be somethign for you to work from anyway.


<?
function online(){

/*This is the database info, use this to make a table in your database
CREATE TABLE online (
id int(10) NOT NULL,
username varchar(50) NOT NULL,
ip char(50) NOT NULL,
start char(50) NOT NULL
);
*/

//This starts the session to see who's online.
global $REMOT_ADDR,$HTTP_COOKIE_VARS;

//Cookie varuables for users.
$id=$HTTP_COOKIE_VARS['user_id'];
$username = $HTTP_COOKIE_VARS['username'];

//The time
$time = time();

//When the user is deleted from the database
$expirytime = $time-500;

//MySQL variables
$mysqlhost = "localhost";
$mysqluser = "user";
$mysqlpass = "pass";
$mysqldata = "database";
$mysqltable = "online";

//Nothing below this needs editing.
$guest = 0;
$mem = 0;
$conn = mysql_connect("$mysqlhost","$mysqluser","$mysqlpass") or die (mysql_error());
mysql_select_db("$mysqldata") or die (mysql_error());
mysql_query("DELETE FROM $mysqltable WHERE (start < $expirytime)") or die (mysql_error());
if(!empty($id)) {
mysql_query("DELETE FROM $mysqltable WHERE id='$id'") or die (mysql_error());
mysql_query("INSERT INTO $mysqltable (id,username,start) VALUES('$id','$username','$time')") or die (mysql_error());
}
else{
mysql_query("DELETE FROM $mysqltable WHERE ip='$REMOTE_ADDR'") or die (mysql_error());
mysql_query("INSERT INTO $mysqltable (id,username,ip,start) VALUES('0','guest','$REMOTE_ADDR','$time')") or die (mysql_error());
}
$whoison = mysql_query("SELECT * FROM $mysqltable") or die (mysql_error());
while($justwho = mysql_fetch_array($whoison)){
if($justwho['id'] == 0) {
$guest=$guest+1;
} else {
$mem = $mem+1;
$who .= $justwho[username];
}
}?>
<table width=125 border=0 cellspacing=0>
<tr><td width=100% valign=top align=left bgcolor=#40407C><strong><font color=#FFFFFF size=1 face=Verdana, Arial><b>Who's Online</b></font></strong></td></tr>
<tr><td valign=top width=100% bgcolor=#A5A5C3 align=center>
<font face=Arial,Helvetica size=1><font color=#000000>
Members: <?echo $mem;?> Guests: <?echo $guest;?><br>
<?echo $who;?>
</font></font>
</td></tr></table>
<?}?>


Had to change it a bit for it to work on my site, but it's something to work from :)