login.php
<html>
<body bgcolor="#CCCCCC">
<center>聊天室</center>
<hr width="60%" />
<form action="chat.php">
<center>
<table>
<tr><td>
选择房间:<select name="room">
<option value="大厅">大厅</option>
<option value="客房">客房</option>
<option value="后院">后院</option>
</select>
</td></tr>
<tr><td>
你的名称:<input type="text" name="name" />
<input type="submit" value="进入" />
</td></tr>
</table>
<hr width="60%" />
</center>
</form>
</body>
</html>
input.php
<html>
<head>
<meta http-equiv="refresh" content="url=input.php?color=<?php echo $color;?>" />
<title>聊天室</title>
</head>
<body bgcolor="#CCCCCC" topmargin="0">
<?php
$name=str_replace("<","<",$name);
$name=str_replace("<",">",$name);
$name=stripslashes(trim($name));
?>
<table border="0">
<form action="input.php" method="post">
<tr>
<td>
位置:<font color="#0000FF"><? echo $room;?></font>
<input type="hidden" name="room" value="<? echo $room;?>" />
名称:<font color="#0000FF"><? echo $name;?></font>
您的表情:
<select name="say">
<option value="说">无所谓</option>
<option value="毫无表情地说">毫无表情</option>
<option value="高兴地说">高兴</option>
<option value="惊奇地说">惊奇</option>
<option value="气愤地说">气愤</option>
</select>
选择颜色:
<select name="color">
<option value="#FFFFFF">白</option>
<option value="#FF0000">红</option>
<option value="#FFFF00">黄</option>
<option value="#0000FF">蓝</option>
<option value="#800080">紫</option>
<option value="#008000">绿</option>
<option value="#00CC00">青</option>
</select>
</td></tr>
<tr><td>
<input type="hidden" name="name" value="<? echo $name;?>" />
内容:<input type="text" name="message" size="75" />
<input type="submit" value="确定" />
</td></tr></form>
<?
date_default_timezone_set('Asia/Shanghai');
$t=date(d日H时i分);
$talk=100;
$r=25;
switch($room){
case '大厅':
$write_file="1.txt";
break;
case '客房':
$write_file="2.txt";
break;
case '后院':
$write_file="3.txt";
break;
default:
$write_file="0.txt";
break;
}
$max_file_size=$r*($talk+15);
$file_size=filesize($chat_file);
if($file_size>$max_file_size){
$lines=file($write_file);
$tmp=count($lines);
$u=$tmp-$r;
for($i=$tmp;$i>=$u;$i--){
$msg_old=$lines[$i].$msg_old;
}
$deleted=unlink($wirte_file);
$fp=fopen($write_file,"a+");
$fw=fwrite($fp,$msg_old);
fclose($fp);
}
$msg=str_replace("\n"," ",$message);
$msg=str_replace("<","<",$msg);
$msg=str_replace("<",">",$msg);
$msg=stripslashes($msg);
if($msg!=""){
$fp=fopen($write_file,"a+");
$fw=fwrite($fp,"\n <font color=$color><b>[$t]$name$say:</b>$msg</font>");
fclose($fp);
}
?>
</table>
</body>
</html>
view.php
<html>
<meta http-equiv="refresh" content="5;url=view.php?room=<?php echo $room;?>" />
<body bgcolor="#000000">
<?
switch($room){
case '大厅':
$write_file="1.txt";
break;
case '客房':
$write_file="2.txt";
break;
case '后院':
$write_file="3.txt";
break;
default:
$write_file="0.txt";
break;
}
$chat_length=25;
$lines=file($write_file);
$a=count($lines);
$u=$a-$chat_length;
for($i=$a;$i>=$u;$i--){
echo $lines[$i]."<br>";
}
?>
</body>
</html>
chat.php
<html>
<head>
<title>聊天室</title>
</head>
<frameset rows="80%,*" cols="*">
<frame src="view.php?room=<?php echo $room;?>" />
<frame src="input.php?name=<?php echo $name;?>&room=<?php echo $room;?>" />
</frameset>
<noframes>
<body bgcolor="#CCCCCC">
</body>
</noframes>
</html>