下面我用读写文本文件的方式给大家简单介绍一下聊天室的制作。该聊天室一共有四个主要的PHP文件:
login.php用来登录
<html> <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> </html>
chat.php为主文件
<html> <head> <title>简易聊天室(作者:东方一蛇(http://phpinto.126.com))</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>
view.php用来显示聊天
<html> <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> </html> input.php用来输入聊天语句
<html> <head> <title>简易聊天室(作者:东方一蛇(http://phpinto.126.com))</title> </head> <body bgcolor="#cccccc" topalign=0> <? #说明:为了避免重复,再加上我本人比较懒,以下所有注释我没有在该文件中说明,您可以在本人的网站上看(http://phpinto.126.com) # 注释1 $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=blue><? echo $room; ?></font> <input type="hidden" name="room" value="<? echo $room; ?>"> 大名: <font color=blue><? echo $name; ?></font><font style="font-size:9pt;color=color:#cccccc"> 有任何问题或建议请去<a href="http://phpinto.126.com" target=home>主页</a>联系<a href="mailto:greenchn@163.net">东方一蛇</a></font><br> </td> </tr> <tr> <td> <input type="hidden" name=&quo |