Jump to content

How many people online.


jackpf

Recommended Posts

Hi all,

To determine who is online on my site, I have a "status" column in my users table, which is updated when users log on/off.

However, if people simply close the window/browser, then my site thinks they're still online.

 

I was just wondering if there's a better way to go about this.

 

Thanks,

Jack.

Link to comment
Share on other sites

Hi all,

To determine who is online on my site, I have a "status" column in my users table, which is updated when users log on/off.

However, if people simply close the window/browser, then my site thinks they're still online.

 

I was just wondering if there's a better way to go about this.

 

Thanks,

Jack.

 

Although I've never done this, I can only offer a generalization.

 

When users just close their browsers, the server/website will still think the user is online. There is no way to log off the user when they close the browser.

 

So the only thing you can fall back on is sessions. Since sessions live on the server for 20 minutes (I think that's the default) You'd have to check if there has been any activity for that user during that time period. And if they have not made any post or logged onto any forum, you can then probably set their account as offline..

 

As for the sessions, you can change that too if you don't like the default...

 

 

Link to comment
Share on other sites

Hi all,

To determine who is online on my site, I have a "status" column in my users table, which is updated when users log on/off.

However, if people simply close the window/browser, then my site thinks they're still online.

 

I was just wondering if there's a better way to go about this.

 

Thanks,

Jack.

 

Although I've never done this, I can only offer a generalization.

 

When users just close their browsers, the server/website will still think the user is online. There is no way to log off the user when they close the browser.

 

So the only thing you can fall back on is sessions. Since sessions live on the server for 20 minutes (I think that's the default) You'd have to check if there has been any activity for that user during that time period. And if they have not made any post or logged onto any forum, you can then probably set their account as offline..

 

As for the sessions, you can change that too if you don't like the default...

 

 

 

Sessions default is 2 hours i believe.

 

Best way to do this (as listed above), and how most forums do this... Every time they visit a page, it updates their last timestamp (and location sometimes). Then when listing, whoever's timestamp is greater than now - X minutes, display.

Link to comment
Share on other sites

Thanks for the response.

Yeah...sessions...I did a quick google on how to get session data, so I could see if the sessions still exist, but couldn't really find a straight answer.

Is this even possible?

 

I think the second approach sounds like a good idea. I could make a function which checks if they're online, something like this-

mysql_connect....etc

$status = $fetch['status']; //status being the unix stamp of the last time they visited a page

if($status + 1200 <= time())
{
$online = 'false';
}
else
{
online = 'true';
}

 

I think I'll go with that, unles anyone has any more suggestion? :)

Link to comment
Share on other sites

Thanks for the response.

Yeah...sessions...I did a quick google on how to get session data, so I could see if the sessions still exist, but couldn't really find a straight answer.

Is this even possible?

 

I think the second approach sounds like a good idea. I could make a function which checks if they're online, something like this-

mysql_connect....etc

$status = $fetch['status']; //status being the unix stamp of the last time they visited a page

if($status + 1200 <= time())
{
$online = 'false';
}
else
{
online = 'true';
}

 

I think I'll go with that, unles anyone has any more suggestion? :)

 

yeah that seems the jist of it......

 

Link to comment
Share on other sites

Actually default session time depends on the server configuration, and when you close the browser, because I've been able to stay logged in on my clients construction site, when I don't have anything set, but WAMP is defaulted to 1/2 hour.

Link to comment
Share on other sites

Best way to do this (as listed above), and how most forums do this... Every time they visit a page, it updates their last timestamp (and location sometimes). Then when listing, whoever's timestamp is greater than now - X minutes, display.

 

I think this is really the way to go for this, no need for sessions. Although not 100% accurate, extremely close (I'll say 90-99%  ;D  )

Link to comment
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.