show users online

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

show users online

Post by malcolmboston »

ok, i was wondering this earlier

what is the simplest (and fail-proof as possible) way to implement a "who's online"?

this is my way of thinking

when a user logs in, run an update query and set the "login_status" as logged in

when a user logs out, run an update query and set it as not logged in

now this is fine and dandy, but what would happen if the user just leaves without logging out? (im guilty of that)

and i know what your thinking now, why doesnt he use a pre-made script, wel no, ive coded my current site completely my-self, by hand, with no help from anyone and im gonna keep it that way :lol:

any ideas would be grand
markbeadle
Forum Commoner
Posts: 29
Joined: Tue Dec 02, 2003 2:50 am
Location: Aachen, Germany

Post by markbeadle »

Not something I have even looked at so you will probably get a better answer but first thoughts....

Most obvious is to time-out logged in people if they do not change anything.
Another possibility is using javascript and onunload event to log user out.

Using the two together should provide a fairly reasonable result.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

hmmmmmm, have never really looked into that, and i despise javascript so i wont be using that

although i have good knowledge of session functions etc, how would it be possible to destroy a session after a set interval, and in turn "tell" the mysql database the guy aint logged in anymore?

i cant see a possible way of doing it like that

thanks for your help btw
markbeadle
Forum Commoner
Posts: 29
Joined: Tue Dec 02, 2003 2:50 am
Location: Aachen, Germany

Post by markbeadle »

Never really played with sessions but would link it to database rather than cookies. If you store the time the person last moved onto the site/within the site/modified something you can use this time with the select statement. Something like "select user_id,username where last_change> (now() - interval '1 hours')". (I use postgres but should be similar for mysql).

Hope that helps
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Try http://www.evilwalrus.com and that snippet searcher. There are various of these useronline scripts that you can take ideas from.

Most common (and what I myself apply) is that you need a timestatmp and use that ($timestamp - 600 (10min)) to determine when and who to delete from the online-table...

Cookies... Not very smart, as the ability to edit/block them are to common these days.

So, insert ip,time; delete from table where time < time-X sec's; select distinct ip's; echo result (basicly)...

Have fun!
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

All this horrible msqaccess all the time!

Why not just examine the sessions folder?
Post Reply