whos online

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gaurav_sting
Forum Newbie
Posts: 19
Joined: Sat Mar 27, 2004 3:45 am
Location: Delhi

whos online

Post by gaurav_sting »

hi everyone

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

thanx alot
Gaurav
User avatar
sutejok
Forum Commoner
Posts: 37
Joined: Wed Mar 24, 2004 4:08 pm

Post by sutejok »

look thru the code of phpnuke
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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.
User avatar
sutejok
Forum Commoner
Posts: 37
Joined: Wed Mar 24, 2004 4:08 pm

Post 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..
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

uhh,

hmm

maybe

just maybe

evilwalrus.com, hotscripts.com
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

whatever the time limit, the above will just delete the old record, and insert a new one, so it doest really matter.
Post Reply