Solved

PHP Members Logged In Count

Posted on 2009-05-13
7
310 Views
Last Modified: 2012-05-06
Given that I have a working login function which verifies against a database, I would like a simple counter on my login page that shows:

Members Logged In : 9

Every time the login is successful, a global variable should be incremented. When the user logs out or the user's session dies, this global variable should decrement also.
0
Comment
Question by:fcqmax
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
SPARC-DESIGN earned 400 total points
ID: 24374410
hi there,
could this be usefull: http://www.sim-php.info/users-online-script.php
0
 
LVL 1

Assisted Solution

by:marty_t
marty_t earned 100 total points
ID: 24374580
Hi,

Best way, being as you're already programming with a DB, is to create a table within that DB for Login Sessions. This can simply have the Users ID in it with a timestamp that gets updated at each page view.

Every time it's updated, purge the data older than say 10 minutes, then count on the amount of rows you have. That will give you the amount of logged in users.

When a user logs out, it deletes them from the table.

Hope that helps.

Marty
0
 
LVL 3

Expert Comment

by:SPARC-DESIGN
ID: 24374606
@marty_t
If you would have clicked the link I posted, you wouldn't type all the text ;-)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:marty_t
ID: 24374780
haha, too true
0
 

Author Comment

by:fcqmax
ID: 24375174
I understand the logic now, but what happens if a user just quits the browser without clicking the logout link to cleanly log out?
0
 
LVL 3

Expert Comment

by:SPARC-DESIGN
ID: 24375216
I understand the logic now, but what happens if a user just quits the browser without clicking the logout link to cleanly log out?
------
The session will die after a few minutes and the row will be deleted from the DB
0
 

Author Closing Comment

by:fcqmax
ID: 31581053
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question