创建 php/mysql/ajax 聊天

发布于 2024-10-09 08:14:00 字数 188 浏览 4 评论 0原文


我将创建一个小项目,其中将是管理员,他必须能够与在线用户聊天(如果他在线)。
我在此类工作方面没有太多经验(例如定义用户是否在线?,或者在我的情况下创建 2 个表 message_from_admin_user 和 message from_user_admin 或一个公用表?),我需要您的帮助。
我将非常感谢您对他们的每一个意见。

I am going to create one small project,where will be admin and he must be able to chat(if he is online) with online users.
I have not a lot of experienc in such work(for example define does user online or not?, or create 2 tables message_from_admin_user nd message from_user_admin in my case or one common table?) and I need Your help.
I will be very grateful to you for every your opinion about them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荭秂 2024-10-16 08:14:00

为什么不使用现有的解决方案,例如:https://blueimp.net/ajax/

以下内容我要定义的表:

  • 包含用户名、密码、上次活动、角色(管理员/用户)的用户表,...
  • 包含 id、ip、用户名、消息、日期时间的聊天记录

Why don't you use an existing solution, like: https://blueimp.net/ajax/

the following tables i would define:

  • user table with username, password, last-activity, role (admin/user) , ...
  • chat history with id, ip, username, message, datetime
雨后咖啡店 2024-10-16 08:14:00

这是课程还是现实世界?

如果您想要从头开始做一些非常简单的事情,我建议跳过任何数据库,而只使用一个登录表单,该表单仅创建一个会话并将用户名保存在文件中。然后,另一个包含对话的文件只是作为数组移动,类似于:

[?php
//login logic...
$username = $_POST['username'];
session_start();
$_SESSION['username'] = $username;
//now add to array of logged in users...
$a = unserialize(file_get_contents('../users.txt');
//maby initiate...
if(!is_array($a)) $a = array();
$a['username'] = sess_id();
file_put_contents('../users.txt',$a);
?]
[html login form here..]

logout-page
[html logout form with logic removing users[$_SESSION['username']...

chat-room:
[? logic collecting new message and shift into array...]
[logic that shows last 20 posts (array)...]
[html with js refeshing as long as textinput is empty...

尽可能简单..

注意,
//t

is it a course or real world?

If you want something really easy from scratch, I'd suggest to skip any db and just have a login-form that just creates a session and saves username in a file. Then, another file with conversation that just shift around as an array, something like:

[?php
//login logic...
$username = $_POST['username'];
session_start();
$_SESSION['username'] = $username;
//now add to array of logged in users...
$a = unserialize(file_get_contents('../users.txt');
//maby initiate...
if(!is_array($a)) $a = array();
$a['username'] = sess_id();
file_put_contents('../users.txt',$a);
?]
[html login form here..]

logout-page
[html logout form with logic removing users[$_SESSION['username']...

chat-room:
[? logic collecting new message and shift into array...]
[logic that shows last 20 posts (array)...]
[html with js refeshing as long as textinput is empty...

as easy as it gets..

regards,
//t

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文