# Track users currently logged in

**URL:** <https://forum.kirupa.com/t/track-users-currently-logged-in/119926>\
**Category:** Uncategorized\
**Created:** [August 19, 2004, 7:07am UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926 "2004-08-19T07:07:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rysolag](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rysolag](https://forum.kirupa.com/u/rysolag)\
**Post date:** [August 19, 2004, 7:07am UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926/1 "2004-08-19T07:07:21Z")

</div>

i am in the process of building a forum from scratch and would like to know how to track the users that are currently logged on. ie like at the bottom of most vbulletin websites it says something like “there are currently 310 users viewing the boards(100 members 210 guests)”.

if someone could please point me to a tut or explanation of how this works.

thanks

---

<div class="post-metadata">

**Author:** ![andr\_in](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/andr_in/32/37_2.png) [@andr\_in](https://forum.kirupa.com/u/andr_in)\
**Post date:** [August 19, 2004, 7:39am UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926/2 "2004-08-19T07:39:32Z")

</div>

I’m afraid with php the only way is to have a number (the count) and then when the user entersa page, php checks if that IP was logged in 10 minutes (or whatever the interval is) ago, and if it wasn’t then it adds the IP and the current time to the database/file, if it was then it does nothing. And to display it it just counts the active users in the last 10 minutes.

But I heard that with asp it is possible to determine when a session is destryed and the rest is simple… when a session is destroyd: decrease count, on creation: increase count.

---

<div class="post-metadata">

**Author:** ![rysolag](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rysolag](https://forum.kirupa.com/u/rysolag)\
**Post date:** [August 19, 2004, 7:58am UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926/3 "2004-08-19T07:58:32Z")

</div>

i understand what you are saying…this should be possible with php and work well enough as vbulletin uses php and pulls it off.

any more advise?

thanks

---

<div class="post-metadata">

**Author:** ![andr\_in](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/andr_in/32/37_2.png) [@andr\_in](https://forum.kirupa.com/u/andr_in)\
**Post date:** [August 19, 2004, 2:10pm UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926/4 "2004-08-19T14:10:02Z")

</div>

nah… google for ‘users online tutorial’ or something for tutes

---

<div class="post-metadata">

**Author:** ![axilant](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@axilant](https://forum.kirupa.com/u/axilant)\
**Post date:** [August 22, 2004, 4:35am UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926/5 "2004-08-22T04:35:38Z")

</div>

ok im going to explain how you can do this, for in real time with php

Have a field in your users table called online

and have it updated with:

```php

 $date = date("U");
 $update = mysql_query("UPDATE table SET online = '$date' WHERE username = '$_COOKIE[user_cookie]'");
 
 //Have that in all the member pages
 
 //Now for the output of who is online:
 $time = date("U");
 $time2 = $time - 700;
 $sql=mysql_query("SELECT * FROM table WHERE online >= '$time2'") or die ("cant do it");
 while($row = mysql_fetch_array($sql))
 {
 print("$row[username]<BR>");
 }
 

```

Thats how you would do that part, just get the num\_rows for the online users.

and for guests, just make a new table in with the users ip, and then do the same with the online part. and so on, i think if you have php knowledge you know what i mean 🙂  
if you still need help please email me, axilant(AT)[gmail.com](http://gmail.com) 🙂

---

<div class="post-metadata">

**Author:** ![ol4pr0](https://avatars.discourse-cdn.com/v4/letter/o/5fc32e/32.png) [@ol4pr0](https://forum.kirupa.com/u/ol4pr0)\
**Post date:** [August 22, 2004, 5:00am UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926/6 "2004-08-22T05:00:58Z")

</div>

Why not setting logged in users to status 1 or active ?? than do a count(\*) WHERE

That together with sessions is my guess all u need. The timer is c00l tho but not sure if that should be ure only check point

---

<div class="post-metadata">

**Author:** ![rysolag](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rysolag](https://forum.kirupa.com/u/rysolag)\
**Post date:** [August 22, 2004, 6:26am UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926/7 "2004-08-22T06:26:56Z")

</div>

how accurate is it to use the IP address? won’t it change over time for most machines?

---

<div class="post-metadata">

**Author:** ![ol4pr0](https://avatars.discourse-cdn.com/v4/letter/o/5fc32e/32.png) [@ol4pr0](https://forum.kirupa.com/u/ol4pr0)\
**Post date:** [August 22, 2004, 6:29am UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926/8 "2004-08-22T06:29:45Z")

</div>

Well not that much… think about it they could use proxy… will they change, yes some do some dont ( most do these days )

---

<div class="post-metadata">

**Author:** ![ol4pr0](https://avatars.discourse-cdn.com/v4/letter/o/5fc32e/32.png) [@ol4pr0](https://forum.kirupa.com/u/ol4pr0)\
**Post date:** [August 22, 2004, 6:34am UTC](https://forum.kirupa.com/t/track-users-currently-logged-in/119926/9 "2004-08-22T06:34:31Z")

</div>

The problem i see is not the count(\*) online users its to check wether they actually closed there browser, for this javascript might actually come in handy  
never done it like this however…

it can be easely used with php. consider the following

```auto

<script language="javascript">
<!-- hide from old browsers
function browser_is_closed() {
// if window.close = true !
<?php
// query 
?>
}
//-->
</script>

```
