Discuz教程网

PHP写的简易聊天室代码

[复制链接]
authicon dly 发表于 2011-8-31 12:12:11 | 显示全部楼层 |阅读模式
index.php
代码如下:

  1. <html>
  2. <head><Title>
  3. 在线聊天
  4. </title></head>
  5. <!-- frames -->
  6. <frameset rows="70%,*" BORDER="0">
  7. <frame name="top" src="_b.php" marginwidth="0" marginheight="0" scrolling="yes" FRAMEBORDER="NO" noresize>
  8. <frame name="bottom" src="_a.php" marginwidth="0" marginheight="0" scrolling="no" frameborder="no" noresize>
  9. </frameset>
  10. <body>
  11. </body>
  12. </html>
复制代码




_a.php
代码如下:

  1. <html>
  2. <title>
  3. 聊天室
  4. </title>
  5. <body TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 >
  6. <?php
  7. $person = @$_POST[person];
  8. $msg = @$_POST[message];
  9. if ($person!="" && $msg!=""){
  10. $handle = fopen("msg.txt","r");
  11. $tot = 0;
  12. $oldmsg = array();
  13. while ($content = fgets($handle)){
  14. $oldmsg[] = $content;
  15. ++$tot;
  16. }
  17. fclose($handle);
  18. unlink("msg.txt");
  19. $fp = fopen("msg.txt","a+");
  20. $time = date("h:i");
  21. fwrite($fp,"<font color="blue">".$person."</font> in <font color="red">".$time."</font>  says that  <b>".$msg."</b><br>"."\n");
  22. for ($i =0;$i<$tot;++$i){
  23. if ($i>50) break;
  24. fwrite($fp,$oldmsg[$i]);
  25. }
  26. }
  27. ?>
  28. <TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
  29. <tr align="left" bgcolor="#666666">
  30. <td height="20">
  31. </td></tr>
  32. <tr bgcolor="#FFCC66">
  33. <td width="1" height="4" ></td>
  34. </tr>
  35. </TABLE>
  36. <table width="100%" border=0 cellspacing=0 cellpadding=0 bgcolor="#EFEFEF">
  37. <tr bgcolor="#666666">
  38. <td align="left">
  39. <table width="100%" height="500" boder=0 cellspacing=0 cellpadding=0 bgcolor="#EFEFEF">
  40. <tr align="left">
  41. <td valign="top">
  42. <font size="-1" color="#666666">

  43. <table width = "100%" border = "0">
  44. <tr>
  45. <form action="_a.php" method = "post">
  46. <td align="left">
  47. <font size="-1">昵称:</font>
  48. <input type="text" name="person" size="12" maxlength="80" value="<?php echo $person;?>">
  49. <br>
  50. <font size="-1"></font>
  51. <textarea type="textarea" name="message" rows="9" cols="150" size = 100></textarea>
  52. <input type="submit" value="发言">
  53. </td>
  54. </form>
  55. </tr>
  56. </table>
  57. </font>
  58. </td>
  59. </tr>
  60. </tr>
  61. </table>
  62. </td>
  63. </tr>
  64. </table>
  65. </body>
  66. </html>
复制代码



_b.php
代码如下:

  1. <html>
  2. <head>
  3. <title>
  4. 聊天室
  5. </title>
  6. </head>
  7. <META HTTP-EQUIV=Refresh CONTENT="5; URL=_b.php">
  8. <body bgcolor="#EFEFEF">
  9. <?php
  10. $handle=fopen("msg.txt","r");
  11. //$oldmsg = array();
  12. while ($content = fgets($handle)){
  13. //$oldmsg[] = $content;
  14. //++$tot;
  15. echo $content;
  16. }
  17. ?>
  18. </body>
  19. </html>
复制代码

20110604120723737.gif





上一篇:把1316这个数表示成两个数的和,其中一个为13的倍数,另一个是11的倍数,求这两个数。
下一篇:PHP小型企业库存管理系统的设计与实现代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 18:45

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表