?
Solved

PHP Members Logged In Count

Posted on 2009-05-13
7
Medium Priority
?
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
SPARC-DESIGN earned 1600 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 400 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

762 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