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?


Recommended Answers

All 5 Replies

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.

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.

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.