Solved

PHP Members Logged In Count

Posted on 2009-05-13
7
307 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now