Gather all user's logged in $_SESSION['user_id']
I am creating a very VERY basic chat script, and i have spent some time trying to find the answer to this before posting but had no luck.
I would like to create a small column on the side to show logged in users.
How might i go about this or maybe point me in the direction of a tutorial?!
Chat scripts are very difficult because this requires that you indirectly connect all of the users to each other through the server, through ONLY page/data requests from the users. (The server cannot request information from the user, only the other way around.)
1. Sessions are ONLY available for an individual user. They're useless if you're trying to connect two users. For ME $_SESSION['username'] is MY name. For YOU $_SESSION['username'] is YOUR username, and there is no way to bridge the two.
2. If you need to connect this info, you will need to do two things:
i) Store the current info in a database, just like you will need to for the messages (text).
ii) Use math (like 1 minute of no activity = left room) to GUESS when a user is no longer in the room.
Or just find an existing chat room. There isn't much out there for PHP/MySQL, and you can actually find some nicer ones for other languages like Java applets, Flash, etc.
There are a couple decent scripts out there, though. The only one I've liked is an addition to SMF (simple machines forums) called "achat", but it only works within that forum. (You could try to extract it and the author is working on an independent version, but it would be a big undertaking or a while to wait.)
Due to the "real time connectivity" (at least in theory) of this, it's quite difficult to do.
Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
okay, so i would need to make a table 'active_user' and store:
user_id | time | active(0/1)<--true false
Then query the database for user's to see the logged in users. But, what if they don't logout.. then i would need to reference a script on every page header, let's say: