开发者

create php/mysql/ajax chat

I am going to create one small project,where will be admin and he must be able to chat(if he is o开发者_StackOverflow社区nline) 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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜