display users online

  • HoocH
  • Student
  • Student
  • No Avatar
  • Joined: Nov 08, 2003
  • Posts: 70
  • Status: Offline

Post February 25th, 2006, 7:27 am

Hello all.
I was hoping someone could write me up a script that shows users online.
The script will be used in a popup. I want to show only the names of a users database.
Thank you for your time and help.

Hooch
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 25th, 2006, 7:27 am

  • onlyican.com
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Nov 20, 2005
  • Posts: 1589
  • Loc: Hants, UK
  • Status: Offline

Post February 25th, 2006, 9:27 am

On the same level.

Anyone know of a tutorial to say Who Is Online, like in PHPBB

I am building a forum from scratch
Heal your mind, and the body will follow
  • Truce
  • Guru
  • Guru
  • No Avatar
  • Joined: Apr 25, 2004
  • Posts: 1477
  • Loc: Washington DC
  • Status: Offline

Post February 25th, 2006, 11:02 am

You're going to need to learn a lot about how sessions work to do that. PHPBB, along with most similar installations, determine's who is online by a reasonable time since the last page load. For example, when I visit Ozzu and go to the programming forum, that's registered in the database along with that time. When you access the same page, it pulls out anybody who visited the page in the last x minutes and displays their username. There are other ways of tracking it down even more with AJAX posting back to the server every x seconds or so, but that's not really neccesary unless you're doing something like a chat.

If you want someone to actually develop the user login script, and a script to show who is online and what page their on, PM me or email me for help.
  • PHP_Guru
  • Graduate
  • Graduate
  • User avatar
  • Joined: Mar 08, 2005
  • Posts: 179
  • Loc: Clermont, FL
  • Status: Offline

Post February 25th, 2006, 7:58 pm

You could also insert a row into a database for each identical IP address of the users who are on the site (that timeout after X amount of time(), I imagine about 300 seconds (5 minutes). For each movement on that IP address, record the users http location ($_SERVER[REQUEST_URI]). That way, you can use mysql_num_rows() to display how many ips are on your site, within a 5 minute timeframe, and be able to see their last known location.
  • HoocH
  • Student
  • Student
  • No Avatar
  • Joined: Nov 08, 2003
  • Posts: 70
  • Status: Offline

Post February 26th, 2006, 6:41 am

Hi Truce.
What I want is a list of who is logged in.
  • xN3uRoNx
  • Beginner
  • Beginner
  • User avatar
  • Joined: Mar 11, 2006
  • Posts: 60
  • Status: Offline

Post March 11th, 2006, 1:55 am

Hey, this is very simple, and i'm here to help! :D

1st off, add this into your members table, or users (whatever you use.)

Online - Varchar(255) default: No

- Next, you're going to create a new file named online.php, or usersonline.php, whatever your heart desires to name it :lol:

Code: [ Select ]
<b>Online Users:</b><BR>

<table border='0' style='border-collapse: collapse' width='100%' id='table1'>
<tr>
<td width='33%' bgcolor='<?=$bgcolor?>' align=''><b>Username</b></td>
</tr>
</table>
<table border='0' style='border-collapse: collapse' bgcolor="black" width='100%' id='table2'>
<tr>
<td width="100%"> <table border='1' style='border-collapse: collapse' width='100%' id='table2'>
<?php include("database_connect.php");

// add a mysql query to gather all the users whos online = Yes.
echo "<ol>";
$result = mysql_query("SELECT * FROM members WHERE online = 'Yes' ");
while ( $online = mysql_fetch_array($result) ) {
  $counter++;

  // have it show up to 99999999999999 on one page.
  
  if ($counter > 99999999999999) { break; }
  if ( $counter % 2 == 0 ) {
    $bgcolor="#bgcolorofyourchoice";
  } else {
    $bgcolor="#bgcolorofyourchoice";
  }
?>
<tr>
<td width='33%' bgcolor='<?=$bgcolor?>' align=''><a href="link=<?=$online['id']?>"><?=$online['username']?></a></td>
</tr>
<?php
} echo "</ol>";
?>
</table></td>
</tr>
</table>
  1. <b>Online Users:</b><BR>
  2. <table border='0' style='border-collapse: collapse' width='100%' id='table1'>
  3. <tr>
  4. <td width='33%' bgcolor='<?=$bgcolor?>' align=''><b>Username</b></td>
  5. </tr>
  6. </table>
  7. <table border='0' style='border-collapse: collapse' bgcolor="black" width='100%' id='table2'>
  8. <tr>
  9. <td width="100%"> <table border='1' style='border-collapse: collapse' width='100%' id='table2'>
  10. <?php include("database_connect.php");
  11. // add a mysql query to gather all the users whos online = Yes.
  12. echo "<ol>";
  13. $result = mysql_query("SELECT * FROM members WHERE online = 'Yes' ");
  14. while ( $online = mysql_fetch_array($result) ) {
  15.   $counter++;
  16.   // have it show up to 99999999999999 on one page.
  17.   
  18.   if ($counter > 99999999999999) { break; }
  19.   if ( $counter % 2 == 0 ) {
  20.     $bgcolor="#bgcolorofyourchoice";
  21.   } else {
  22.     $bgcolor="#bgcolorofyourchoice";
  23.   }
  24. ?>
  25. <tr>
  26. <td width='33%' bgcolor='<?=$bgcolor?>' align=''><a href="link=<?=$online['id']?>"><?=$online['username']?></a></td>
  27. </tr>
  28. <?php
  29. } echo "</ol>";
  30. ?>
  31. </table></td>
  32. </tr>
  33. </table>


- Thirdly, your going to need to add a mysql_query to your login page, and your logout page. :P

Code: [ Select ]
mysql_query("update members set online = 'No' where id = '$view[id]'") or die ("error: " . mysql_error()); // will update it when user logs out.


Code: [ Select ]
mysql_query("update members set online = 'Yes' where id = '$view[id]'") or die ("error: " . mysql_error()); // will update it when user logs in.



thats basically it, accept you chage everything so it will fit your coding needs/sql :) oh, and the view[id] needs to be changed to whatever you use for that aswell. :) Good luck, I hope this helps! (I tried to explain the best I could.)

again, good luck in creating this, and I hope this works for you!. If you have a question, just ask :)
  • Vincent
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 01, 2005
  • Posts: 721
  • Loc: Brisbane, Australia
  • Status: Offline

Post March 11th, 2006, 2:18 am

we're probably going to make a sticky out of this subject some time because there is a large number of people who come to this site asking for the same thing and basically the same thing is said over and over again.

what we need is a tutorial that tells you what options there are to do this and how you would attempt to do this each time, with a bit of code provided to give the programmer a bit of a head start for their own way of doing it
"Chris" Vincent's Portfolio
  • xN3uRoNx
  • Beginner
  • Beginner
  • User avatar
  • Joined: Mar 11, 2006
  • Posts: 60
  • Status: Offline

Post March 11th, 2006, 2:23 am

Vincent, agreed. I just gave a quick basis of this code, and the most simplest way of doing it, as I could think of many other ways of coding this :D :wink: but, this code works just fine for me, and it gives a simple edit to the look :)
  • onlyican.com
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Nov 20, 2005
  • Posts: 1589
  • Loc: Hants, UK
  • Status: Offline

Post March 11th, 2006, 6:44 am

One problem I see, if the person closes the window instead of logging out, they will always be logged in.
Heal your mind, and the body will follow
  • xN3uRoNx
  • Beginner
  • Beginner
  • User avatar
  • Joined: Mar 11, 2006
  • Posts: 60
  • Status: Offline

Post March 11th, 2006, 11:10 am

onlyican.com wrote:
One problem I see, if the person closes the window instead of logging out, they will always be logged in.


thats why you would include your header page, or head page which has all that info in it :wink:
  • onlyican.com
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Nov 20, 2005
  • Posts: 1589
  • Loc: Hants, UK
  • Status: Offline

Post March 11th, 2006, 11:20 am

huh!
Heal your mind, and the body will follow
  • xN3uRoNx
  • Beginner
  • Beginner
  • User avatar
  • Joined: Mar 11, 2006
  • Posts: 60
  • Status: Offline

Post March 11th, 2006, 11:46 am

<?php include("page.php"); ?>

^^that page will have all the info about if the user is logged in or not :wink:
  • onlyican.com
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Nov 20, 2005
  • Posts: 1589
  • Loc: Hants, UK
  • Status: Offline

Post March 11th, 2006, 11:51 am

ok, from my understanding
when somone loggs in, we update the table to say online

when someone logs out, we update the table to say offline

What happens if someone does not log out, they close there browser,

I never log out, I always close by browser.

How can we tell that the user has closed the browser or still online?
Heal your mind, and the body will follow
  • xN3uRoNx
  • Beginner
  • Beginner
  • User avatar
  • Joined: Mar 11, 2006
  • Posts: 60
  • Status: Offline

Post March 11th, 2006, 12:04 pm

You could read the timestamp of the users most recent page hit, and if it has been 15 minutes of inactivity, that user gets logged out. Than, it will be overwritten with the current time. (the new timestamp.) :)
  • onlyican.com
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Nov 20, 2005
  • Posts: 1589
  • Loc: Hants, UK
  • Status: Offline

Post March 11th, 2006, 12:07 pm

I have already posted that in a prev topic today

My way of doing,

NOTE: NOT TESTED

When a user uses a page, they go into a db, noted at that time.

When someone loads a page a query reads select all users where last_online greater than 15 mins ago.

(code will be a bit longer)
Heal your mind, and the body will follow
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 11th, 2006, 12:07 pm

Post Information

  • Total Posts in this topic: 47 posts
  • Users browsing this forum: No registered users and 221 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.