Page 1 of 1

whos online

Posted: Mon Jun 07, 2004 11:32 pm
by gaurav_sting
hi everyone

can anybody help me telling that how can we know number of users online

thanx alot
Gaurav

Posted: Tue Jun 08, 2004 1:49 am
by sutejok
look thru the code of phpnuke

Posted: Tue Jun 08, 2004 2:33 am
by qads
phpnuke? 8O

by the time he finds it in there, he can make his own :lol:

soemthing like this....

make a table with these fields:

ID int, auto inc
ip varchar 20
stamp int 20


then, make a function which checks if user ip is in the database or not, and also it should delete any records older then 5 or so mins, i.e.

Code: Select all

<?php
function users_online()
{
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();
$num = mysql_num_rows(mysql_query("select `ID` from TABLENAME where `ip` = '$ip' LIMIT 1"));
if($num != 1)
{
$query = mysql_query("INSET INTO TABLENAME VALUES ('','$ip','$time')");
}
$old = $time - 300//5 mins
$delete = mysql_query("DELETE from tablename where `stamp` <= '$old'");
//check number of users online...
$num = mysql_num_rows(mysql_query("select `ID` from TABLENAME"));
return $num;
}
?>
include this function on everypage.

Posted: Tue Jun 08, 2004 11:21 am
by sutejok
hmm. i think make it more than 10 minutes. I mean, just in case someone is reading a long article while he is logged in which is going to take him more than 5 minutes..

Posted: Tue Jun 08, 2004 6:25 pm
by tim
uhh,

hmm

maybe

just maybe

evilwalrus.com, hotscripts.com

Posted: Tue Jun 08, 2004 10:10 pm
by qads
whatever the time limit, the above will just delete the old record, and insert a new one, so it doest really matter.