Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.