本文实例讲述了PHP+MysqL+ajax轻量级聊天室实现方法。分享给大家供大家参考,具体如下:
做了一个QQ聊天交友网站,想加个聊天的功能,于是做完用PHP做了简单又强大的聊天室
代码如下:
dbconnect.PHP
PHP;">
3. 编写ajax发送和接收函数:
PHP;">
PHP;">
PHP
header("Content-Type:text/html;charset=gb2312");
header("Expires: Thu,01 Jan 1970 00:00:01 GMT");
header("Cache-Control: no-cache,must-revalidate");
header("Pragma: no-cache");
require_once('dbconnect.PHP');
db_connect();
$sql = "SELECT *,date_format(chatdate,'%Y年%m月%d日 %r') as cdt from chat order by ID desc limit 200";
$sql = "SELECT * FROM (" . $sql . ") as ch order by ID";
$result = MysqL_query($sql) or die('Query Failed: ' . MysqL_error());
// Update Row Information
$msg="";
while ($line = MysqL_fetch_array($result,MysqL_ASSOC))
{
$msg = $msg . "