Jump to content

Recommended Posts

Ok i read all of the post about showing online users but im stuck

 

I tried to make a script which shows which one is logged in.. I have a table like this

 

uname | ip | time | guest

 

and here is the code im using to show the number of members and guest ..

 

$uname = $_SESSION['user_name'];
if (!$uname) { $guest = 1; } else { $guest = 0; }
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();
$query = "SELECT * FROM user_online WHERE ip = '$ip'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 1)
{
      $query2 = "UPDATE user_online SET uname='$uname',time='$time',guest='$guest' WHERE ip = '$ip'";
      $result2 = mysql_query($query2);
}
else
{
      $query2 = "INSERT INTO user_online (uname,ip,time,guest)VALUES('$uname', '$ip', '$time','$guest')";
      $result2 = mysql_query($query2);
}

$time3 = time() - 300;
$query3 = "DELETE FROM user_online WHERE time < $time3";
$result3 = mysql_query($query3);

$query4 = "SELECT * FROM user_online WHERE guest = '1'";
$result4 = mysql_query($query4);
$guestonline = mysql_num_rows($result4);
$query5 = "SELECT * FROM user_online WHERE guest = '0'";
$result5 = mysql_query($query5);
$memonline = mysql_num_rows($result5);
$totalonline = $guestonline + $memonline;
echo 
"Guests: $guestonline<br />
Members: $memonline<br />
Total: $totalonline<br /><br />";

 

this is the code im using to show the names of logged users..

 

$sql = "SELECT * FROM user_online WHERE guest = '0'";
$result = mysql_query($sql,$conn);
while($sql = mysql_fetch_object($result)){
   $_uname = $sql -> uname;
   echo $_uname;
   echo "<br>";
   }

 

whats happening is, when a person logs out, the name remains there. is there a way to remove the name once the user has logged out? Would be nice if someone could help me with it and show me the right path to it. Maybe i took the wrong way to do it.

 

 

 

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

Usually you cannot tell when someone logs out. They might close their browser, or click the 'logout' link or their computer might crash.

 

Most system I see show a 'People Logged in the past 5 mins' and then query to see when the last activity was of the person on the site. If there was no activity for more than 5 minutes the system would assume they 'logged' out :)

 

Link to comment
https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-357461
Share on other sites

I made something similiar to this in a project I was doing. I probably did it the hard way, but here goes (Note: This is only the basics...).

 

I have a table... User, Date, Time, Status.

When a user logs in, coding is used to update the table (or add a new row) with the date and time. Status is set to 'On Line'.

 

When a user goes to a page (Home, Contact, About, etc), coding at the top of the page updates the table with the new date and time, or updates the table by setting the status to 'Off Line' and then adds a new row with 'On Line'. There is also code to check the table for all 'On Line' status's. It uses a pain in the butt formula to check all the dates/times to see if any are older than say 10 minutes. If the date/time is older than 10 minutes, then the user has not moved for at least that long. This date/time check is for ALL 'On Line', not just the current user. If it finds an 'On Line' row older than 10 minutes, it changes the status to 'Off Line'. If that user was really on-line, then when they move, a new line will be added for them and they will be 'On Line' again.

 

Hope this helps.

Link to comment
https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-358765
Share on other sites

if you can see in this forum when you log out your name is deleted in your page but not in our page unless we refresh the page

 

but if you want it that way you can try a frame where in the top page is refreshing every 10 seconds etc...

 

obviously it won't go on ur page.. but can you plz tell me if there is some kind of error in my code? im new to this stuff but still trying my best to get working..

 

I somehow manage to get the name to appear on a page.. somehow, refreshing it every 50 seconds or whatsoever would be better i presume.. the ones logged in would be able to know which one is still online

Link to comment
https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-358838
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.