php/mysql show logged in

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
linuxbox
Forum Newbie
Posts: 18
Joined: Fri Dec 12, 2003 5:16 pm

php/mysql show logged in

Post by linuxbox »

hey there, i have recently created a login/registration script and on my admin screen i'd like to show "users currently logged in" along with what page they are viewing. i'm using sessions but not using session id's in the cookie or anything that auto logs a person back in. is there a way to show all sessions? i have no clue on how to show users currently logged in for admin purposes.

thanks.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Each time a user loads a page store in a database the page they loaded, the time, username, IP etc. Then you can just print this info on your page. Of course only keep one record per username.

When displaying the page you can then just call the info from the database where the last page loaded time is without a certain time out value - like 5 mins.

You can then also use this to see the last time a user was seen - which can help you if you ever need to remove inactive users from the site.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Then arises this simple problem : What if there are guests? How do I show people who aren't guests? 1 solution to this is to assign the guest a unique guest-only cookie. Then, use the quest's IP to assign uniqueness to it in the database. From there, it shouldn't be hard to tell how many guests you have on your site. ^_^
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You can just add guests to the same database table, but set the username to NULL and then identify them by their IP. Then make sure to remove this record if the guest logs on and becomes a member.
linuxbox
Forum Newbie
Posts: 18
Joined: Fri Dec 12, 2003 5:16 pm

Post by linuxbox »

kettle_drum wrote:Each time a user loads a page store in a database the page they loaded, the time, username, IP etc. Then you can just print this info on your page. Of course only keep one record per username.

When displaying the page you can then just call the info from the database where the last page loaded time is without a certain time out value - like 5 mins.

You can then also use this to see the last time a user was seen - which can help you if you ever need to remove inactive users from the site.
NEVERMIND--i figured it out.. DOH.. create another table frigg'n DOH!
geez, what am i smok'n. must be crack.
Post Reply