1,105,578 Community Members

Check for online users

Member Avatar
Kratoswoo
Light Poster
33 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

So I have been working on something that will check if a user is online or offline.

I have the login page set up adn when you loggin, it will take you to the datase that shows all the users.

I have a row called "UserOnline" and I want it so when you are signed in it is change to a 1.
This way I can highlight the name green or something so show that, that person is online.

Any help?

Thanks

Member Avatar
JorgeM
IT Addict
6,414 posts since Dec 2011
Reputation Points: 581 [?]
Q&As Helped to Solve: 963 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
0
 

So there are various ways to handle this, you can do it server side or client side.

I have a row called "UserOnline" and I want it so when you are signed in it is change to a 1.

so a simple way to do this is to have two images.. 0.jpg and 1.jpg. When you query your DB table for the status of a user, you get a 0 or a 1 (i assume)... well, then just use that information and append ".jpg" so that you can show an online or offline status by dynamically chaning which image you plan on showing...

There are other ways as well, but I think this is a very simple and easy approach.

Member Avatar
hometownnerd
Junior Poster in Training
50 posts since Sep 2007
Reputation Points: 13 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 4 [?]
 
0
 

and something to think about is how will you know a user is offline? We have a login system in place that works fairly well, but detecting a user leaving the system is very difficult, we use session and forms verification and still cannot detect a user has simply either closed the browser or just left the webpage. Although has been a while since I tried to find a way to do this, so maybe it is possible with jQuery etc.

Member Avatar
GliderPilot
Posting Whiz in Training
296 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

Create a LastOnline timestamp row in the DB.

When someone is logged in, everytime they load a page, update the timestamp

When you want to know who is logged in do a DB query and get everyone who's timestamp is within the previous x amount of time. For example on our site I have it set to 5 minutes, so I run a query to select all users who's timestamp is within the last 5 minutes. If they have done something within the last 5 minutes there is a good chance they are logged in. It's not 100% accurate but's it's fairly close, simple and effective

Member Avatar
Kratoswoo
Light Poster
33 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks everyone for help.
Finnaly got it working but I had to do userIsOnlineTimeWindow ="1" to allow a "sign out"
Is there any way of setting it to 0 so they are signed out right away instead of in 1 minute.

Then to make the users that are online, make them show up in green or do what Jorge says and use a "Online" "Offline" icon.

Member Avatar
GliderPilot
Posting Whiz in Training
296 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

Setup two CSS classes one for offline and one for online. Simple if statement, if they are online make their name class="online" if they're offline make their name class="offline" than you can set all the coloring and formatting to the text you want in CSS

Question Answered as of 1 Year Ago by GliderPilot, hometownnerd and JorgeM
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article