Solved

PHP Members Logged In Count

Posted on 2009-05-13
7
312 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 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
Industry Leaders: 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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