使用PHP 1-1聊天系统/ MySQL的 [英] 1-1 Chat system using PHP/MySQL

查看:133
本文介绍了使用PHP 1-1聊天系统/ MySQL的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

项目:这需要1-1私人聊天的应用程序。
目前的系统:在应用程序中当前登录系统使用,为用户留在记录一个cookie系统

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.

我知道如何实现聊天系统(我刚刚看了一下彗星,后来可能会实现它,但现在,我打算使用定时器使用基本AJAX);聊天将存储在聊天中的文本/ xml文件,并且将被存档到数据库中,一旦它的完成。的文件名将存储在数据库中的聊天开始时,一旦检索,将被存储在cookie中(该数据库将原封不动,除了聊天的开始和结束的时)。

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).

问题:用户不能启动与另一个用户的交谈,除非他们都在网上。我如何设计系统,使得聊天只能启动如果两个用户是否在线?
我并不真的需要特定的code,使得它的工作只是逻辑。

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.

推荐答案

在登录用户在你的网站,并保持你发送一个AJAX平每5秒到服务器,服务器将更新的ping时间。 所以你可以列出你的网上找人在这个时候,如果平时间大于5秒,这意味着你的用户将被注销或关闭浏览器。

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.

这篇关于使用PHP 1-1聊天系统/ MySQL的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆