Below I use to read and write text file of the way to give you a brief introduction to chat room production. There are four main PHP files in the chat room:
Login.php used to log in
<body>
<form action="chat.php">
房 间:<select name="room" >
<option value="大厅">大厅</option>
<option value="客房">客房</option>
<option value="后院">后院</option>
</select>
您的大名:<input type="text" name="name">
<input type=submit value="进入">
</form>
</body>
chat.php main file
<title>简易聊天室(作者:东方一蛇(http://phpinto.126.com))</title>
<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>
View.php used to show chat
<meta http-equiv="Refresh" content="5; url=view.php?room=<?php echo $room; ?>">
<body bgcolor="#cccccc">
<?
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_lenght = 25;
$lines = file($write_file);
$a = count($lines);
$u = $a - $chat_lenght;
for($i = $a; $i >= $u ;$i--){
echo $lines[$i] . "<br>";
}
?>
</body>