【问题标题】:create php/mysql/ajax chat创建 php/mysql/ajax 聊天
【发布时间】:2011-05-30 17:51:13
【问题描述】:


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

【问题讨论】:

    标签: php mysql ajax chat


    【解决方案1】:

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

    我将定义以下表格:

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

    【讨论】:

      【解决方案2】:

      是课程还是现实世界?

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

      [?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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-08
        • 2011-07-12
        • 2017-09-10
        • 2012-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多