index.php//#############(主界面);
[PHP]
聊天室
<script language="JavaScript">
showtime=new array();
//记录聊天的时间
chatusername=new array();
//记录聊天用户的id
lines=new array();
//记录聊天的内容
</script>
[/PHP]
LIST.PHP//###############信息显示模块
[PHP]
<script language="JavaScript">
for(i=0;i' + top.showtime
+': ');
document.write('' + top.chatusername
+ '--> ');
document.write('' + top.lines
+ '');
document.write(',br>');
}
</script>
[/PHP]
POST.PHP//##############发送模块
[PHP]
无标题文档
<?php
session_start();
session_register("times");
if(!isset($time))
{
$times="0";
}
if(isset($msg) && $msg!="" && $chatuser!="")
{
$link=mysql_connect("localhost","root","asdfghjkl") or die("connect error");
mysql_select_db("sm",$link);
$now=date("h:i:s",time());
$query="insert into chatroom(times,chatuser,msg) values('$now','$chatuser','$msg')";
mysql_query($query,$link);
//写入数据
$query="select * form chatroom where times>'$times'";
$result=mysql_query($query,$link);
echo "<script language='javascript'>";
while($row=mysql_fetch_array($result))
//读取数据
{
if($row["times"]>$times)
{
$times=$row["times"];
}
echo "top.chatusername[top.lines.length]='".$row['chatuser']."';\n";
echo "top.showtime[top.lines.length]='".$row['times']."';\n";
echo "top.lines[top.lines.length]='".$row['msg']."';\n";
}
echo "top.list.location.reload();";
//刷新显示
echo "</script>";
}
?>
[/PHP]
get.php//###########信息接收模块
[PHP]
<?php
session_start();
session_register("times");
//这里使用session来记录已经刷新的时间
if(!isset($times))
{
$times="0";
}
$link=mysql_connect("localhost","root","asdfghjkl");
mysql_select_db("sm",$link);
//查询数据库
$query="select * from chatroom where times>='$times'";
$result=mysql_query($query,$link);
//读取刷新以后的记录
$msg=array();
echo "<script language='javascript'>";
//用php输出javascript语句
while($row=mysql_fetch_array($result))
{
if($row["times"] >=$times)
{
$times=$row["times"];
}
echo "top.chatusername[top.lines.length]=".$row['chatuser']."';\n";
echo "top.showtime[top.lines.length]='".$row['times']."';\n";
//输 出javascript语句,给数组与值
echo "document.write(top.lines.length);";
}
echo "top.list.location.reload();";
//刷新显示
echo "</script>";
?>
聊天室
[/PHP]
提示数组定度出错。
array()
语法错误:
window.setinterval('location.reload()
i