doutuo7609 2012-01-10 16:38
浏览 55
已采纳

1-1使用PHP / MySQL聊天系统

Project: An application that requires a 1-1 private chat.
Current system: The current login system in the application uses a cookie system for the users to remain logged in.

I understand how to implement the chat system (I just read about Comet, and might implement it later, but for now, I plan to use basic AJAX using a timer); the chat will be stored in a text/xml file during the chat, and it will be archived into the database once it's finished. The filename will be stored in a database when the chat starts, and once retrieved, will be stored as a cookie (the database will be untouched, except for when the chat starts and ends).

Problem: A user cannot start conversations with another user unless they are both online. How do I design the system such that the chat can only start if both users are online?
I don't really need specific code, just the logic of making it work.

  • 写回答

3条回答 默认 最新

  • duanduo3712 2012-01-10 16:59
    关注

    When a user is logged in your site and stays you send a ajax ping on every 5sec to server, and the server will update the time of the ping. And so you can list your online people looking on this time, and if the ping time is greater than 5 sec that means your user is logged out or closed their browser.

    Also you can do the away status with the same mechanism using browser focus events.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题