Page 1 of 1

Need help on simple prob regarding 'whos online' thingy

Posted: Fri Feb 27, 2004 10:03 pm
by VanCe
Dear programmers,

i want to make a 'who's online' function in my website .. but i do not know how to make tat appear in my webpage... i have the script called 'online.php' but how do i put it so tat it automactically shows when users enter the site without having to click any link like "click here to show who's online'

heres my online.php script

<?php

function whos_online() {
global $REMOTE_ADDR;

mysql_connect("localhost","root","");
mysql_select_db("Login");

$exp = time() + 300; //300 seconds for 5 minutes
$time = time();

$query = "select * from latest where ip='$REMOTE_ADDR'";
$result = mysql_query($query);

if(mysql_num_rows($result) == 1) {
$query = "update latest set time='$exp' where ip='$REMOTE_ADDR'";
mysql_query($query);

}else{
$query = "insert into latest VALUES('$REMOTE_ADDR','$exp')";
mysql_query($query);
}

//delete IP's that have expired...
$query = "delete from latest where $time > time";
mysql_query($query);

$uonline = mysql_num_rows(mysql_query("select * from latest"));

//print the variable on our page!
print($uonline);

}

whos_online();
print(" users online in the last 5 minutes");

?>

is it i paste this code into the html ? i tried but it doesnt work....
please help me~ im a newbie.... :(

Posted: Sat Feb 28, 2004 12:29 am
by AbelaJohnB
Andrew pretty much explains the entire script (section by section) and how to get it to work at: http://arc.ireed.net/tutors/archive/php/001/index.php

Posted: Sun Feb 29, 2004 7:04 pm
by VanCe
hmm... but how to i use this code...erm i mean how do i run it automatically when the page loads... do i need to put in any code in the html to run this script?

thx thx