Advanced Search

Results 1 to 3 of 3

Thread: Gather all user's logged in $_SESSION['user_id']

  1. #1
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default Gather all user's logged in $_SESSION['user_id']

    Hi,

    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?!

    Thanks everyone!

    Cory

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    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

  3. #3
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    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:

    require_once('active_user.php');

    And in the active_user.php we will have a query that runs through the table 'active_user' and cleans up any rows that are older than '15min'. And just to be safe incase the person happens to be reading something on a page for more than 15min.., i will put a javascript on all common pages to renew the logged in users $row['time'] so they don't get accidentally cleaned out by the script running when someone else log's in. As long as their browser is open, they will stay active according to the table.

    Now...

    Where do i get this javascript to do that!! ---> off to the javascript forum!

    Thanks Dan!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •