Hi friends...

My friend s doing an online project...

He wants to know how many users(REGISTERED) are LOGGED-IN CURRENTLY in his site...

i.e if i'm ADMINISTRATOR of this DANIWEB, i want to know the USERS CURRENTLY LOGGED-IN...

I need the logic for this...

Help me...

Thanks in advance...

Recommended Answers

All 2 Replies

The registered users would be references in a table in the database. In the same table, a column should be created (name: Login)to store following values

1. When the user logs in using the login form update the table and set "logged in" status in login column for that user.
For e.g. if I have logged in, the website would update the login column in my row to say I have logged in.

2. When the user logs out using the logout link, the table can then be reupdated to show that the user has logged out.

But now the problem arises as to What if the user just closes the window. Here a decision has to be made whether the user should be kept logged in or the system should log the user out.

To keep the user logged in, create a cookie on his system which would reference him next time he comes to the page. The cookie would allow him into his session without an authentication being required.

To log him out, use a javascript onunload() event and AJAX. When a user just closes the window the onunload event, would trigger the AJAX function which would call the php code to change the database logging the user out.

It all depends on how advanced you want to get with the code.

Wish your friend good luck with his project!

Member Avatar for diafol

The other problem with this is what to do with the 'logged-in' field.

The only time you can really trust a 'logged-out' value is when a user physically logs out. What you can do is save the 'last page impression' - ie. the timestamp of the last time a page in the site was accessed. If this is > say 20 minutes, logout the user. UNLESS, you have a 'remember me' function.

Be a part of the DaniWeb community

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