0

I've decided to create a web based chat system for the experience. I'm using a mixture of AJAX(jQuery), PHP, and JSON to transfer the data. Now that I've started thinking about certain things, I've come to a mind block.

Right now, I use javascript to post the last loaded message id to a php file that queries the data and echoes new posts in json and then displays those posts in order on the page. However, the dates don't reflect the current time for the user. Since I use php to get the current time, I have no idea how to display the correct time to the user which takes into account of their time zone. Second, how would I incorporate a who's online list with this method? I could create a separate table and update it when a user creates a session and delete their name when they end the session; but what if they don't close it properly? Should I just add their last sent message into the the table and if it's been about 5 minutes since their last message consider the user disconnected? Lastly, is the method I'm using to collect new posts efficient? This there a better way to go about this? I appreciate any input.

AllofHumanity
  • 59
  • 1
  • 5

1 Answers1

0

This seems related: Determine a User's Timezone

I'm going to make you go there for the code snip so you give proper credit with your upvotes.

I get the impression that Javascript is the best/easiest way to get that data.

What I would probably do is use GMT or some other fixed time zone for all your server stuff and then just adjust that with js once it hits the browser depending on their time zone. Either that or just collect it once at the start of the conversation and adjust your output accordingly. There might be advantages to either way.

Edit: Oh yeah, about the "who's online" I think you're headed in the right direction. I might suggest 2 lists. "Who's active" and "Who was active recently"

That way you can put people inactive after 5 mins and consider them disconnected after 10 or something. I guess it's about the same but it seems more accurate to me somehow.

The other option would be to set an ajax request to automatically fire of a request every minute or so. When they stop then you know the user is gone.

Community
  • 1
  • 1
Syntax Error
  • 4,475
  • 2
  • 22
  • 33