Check if some user is active

Hi guys! :)

I have to implemente a simple jquery chat in a project I’m working on, and I can’t figure how I could check if a determined user has an active session, this is, is logged in (and active).

Any advice would be very welcome.

Thanks in advance!

u can update table when someone is logged in system mark as active

and on logout update it.


Like "rups g" said you somehow have to keep track of the users.

Not sure if it is the best solution but take a look at:

to get an Idea how to realize this…


Thanks @rups and @MetaCrawler!

I was thinking something similar, just like this:

The problem with this approach in my situation is that I need to keep track if the user has an opened window.

The chat script I’m using sends a ajax request to check messages, so I better will use this and check if the user is active every, let’s say, every minute.

First, I will create a table like this:

CREATE TABLE `chat_status` (


    `user_id` INT(11) NOT NULL,

    `last_time_active` TIMESTAMP NOT NULL,

    PRIMARY KEY (`id`))

ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;

And then, with ajax, I will update the timestamp while the user has an opened window.

Then, I can keep track of the activity.

What do you think?

u need to update user status in UserTable.

I would prefer to separate the "system wide" status (Registered, Accepted, Blocked, etc) to this status (online/active).

okay it is also good idea to separate the status. u used table name "chat_status" so i thought it should cover only chat data status not user logged status.

just naming choice…

Nice catch!

I will try a better name.