create php/mysql/ajax chat
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
精彩评论