Jump to content

Online users


dean7

Recommended Posts

Hi all, I have a user online script witch my friend helped me with but it only counts the ammount of users online.

 

<?
session_start();
$session=session_id();
$time=time();
$time_check=$time-600; //SET TIME 10 Minute

$host="***************"; // Host name
$username="**********"; // Mysql username
$password="********"; // Mysql password
$db_name="*********"; // Database name
$tbl_name="online_users"; // Table name

// Connect to server and select databse
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name WHERE session='$session'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count=="0"){
$sql1="INSERT INTO $tbl_name(session, time)VALUES('$session', '$time')";
$result1=mysql_query($sql1);
}
else {
"$sql2=UPDATE $tbl_name SET time='$time' WHERE session = '$session'";
$result2=mysql_query($sql2);
}

$sql3="SELECT * FROM $tbl_name";
$result3=mysql_query($sql3);

$count_user_online=mysql_num_rows($result3);

echo "User online : $count_user_online "; 

// if over 10 minute, delete session 
$sql4="DELETE FROM $tbl_name WHERE time<$time_check";
$result4=mysql_query($sql4);

mysql_close();

?>

But how would i make it so it would show the users that are online and count them at the same time?

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/159142-online-users/
Share on other sites

kinda need to know whats in the 'online_users' table,

if you have usernames then a simple loop would work

ie

$sql3="SELECT * FROM $tbl_name";
$result3=mysql_query($sql3);
//start add 
$users = array();
while($rows = mysql_fetch_array($result3))
{
$users[] = $rows['user'];
}
var_dump($users); //output
//end add
$count_user_online=mysql_num_rows($result3);

Link to comment
https://forums.phpfreaks.com/topic/159142-online-users/#findComment-839298
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.