Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need an Idea: checking users if logged in.

Status
Not open for further replies.

perlone

Programmer
May 20, 2001
438
US
Hi,

I need to check how many users are actually logged into the server or the database. I don't have an idea of how to check that. I was wondering if anyone could give me an idea so I can write the code. Thanks if you can help.

There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
That is a problem using HTTP. Since HTTP is non-persistent, it does not support the idea of 'logged in'. A web server only knows that it receives requests for pages and it tries to serves those request. As far as the web server knows, no single request is related to any other request. This is quite different from sitting at a unix prompt, logged into a unix box, where the OS is paying attention until you log out. With HTTP you can track log-in events, html hidden fields, and cookies to try to catch some information about how long someone stays on your site, but ..... there is no such thing as a log-out. Therefore, it is possible for a user to leave your site, then return via their back button and you'd never know the difference.


Exactly what information are you trying catch?
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Hello,

I'm trying to get all the users from the database who is active atleast 2 or 5 minutes. It doesn't have to be accurate but close. For the databse part, i'm using mysql. Do you have any idea for how to figure out how many users are active atleast 2 to 5 minutes? I could figure out if the user is logged in but I lose control whether they're logged out.

An example of my mysql table:

[uid] [username] [upass] [uemail]
x xxx xx xxx

I could add an extra field called [logged] and add an value of "1" if they logged using the login field but i don't how to check how many users are active for like 2 minutes or logged out. Thanks again for your reply. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
You could try to send a little Javascript to the user that counts down from 5 minutes. After 5 minutes you let the Javascript send a message to your Perl script so that is knows the user is still active.

If you get this to work, please let me know, 'cause I'm trying this myself too. If I succeed I'll let you know...
 
Another thing you could do is add a table that sets a date/time stamp and an ID to show when someone performed an action on the database (logging their requests basically). Something to the effect of:

seq_id date/time user_seq_id function_id
### ### ### ###

Then have an associated table of functions that you'd like to have logged with a sequence ID to correspond with the function ID. This way, you could currently only log login and log out times, but in the future, it would be simple to add other features such as commiting changes to their profile, or adding a news article, etc. (Not sure what your site is for) The function table would be as simple as:

seq_id function
### ******
 
I like the time stamp idea but it requires the updating of the database of every run of the script and could cause unnecessary cpu usage later down the line. I think this is unavoidible if you want this function. My suggestion would be to add a last login field to the users infromation. This would be a little more information to an admisitrator.

I would also create a seperat table entirly for this purpose to speed the database access or use a simple txt file. Each run of the script have the program check this table and perform these functions to it.
1- add the current login
Name timein
XXX XXX
2- Remove any entries whose last timein is grater than your time specified.
3- output data
 
Why not try this:

Everytime a new user comes to the site it logs there ip and adds there information to the database. It then ignores there ip for 2 hours.

Then you write a script that gets information from database where the ip was added not before 5 minutes ago.
 
Thank you all, I will try it all! There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top