php写的简易聊天室代码
发布时间:2020-12-13 05:54:25 所属栏目:PHP教程 来源:网络整理
导读:index.php div class="codetitle" a style="CURSOR: pointer" data="40516" class="copybut" id="copybut40516" onclick="doCopy('code40516')" 代码如下: div class="codebody" id="code40516" 在线聊天 frameset rows="70%,*" BORDER="0" _a.php div class
index.php <div class="codetitle"><a style="CURSOR: pointer" data="40516" class="copybut" id="copybut40516" onclick="doCopy('code40516')"> 代码如下:<div class="codebody" id="code40516"> 在线聊天 <frameset rows="70%,*" BORDER="0"> _a.php <div class="codetitle"><a style="CURSOR: pointer" data="32230" class="copybut" id="copybut32230" onclick="doCopy('code32230')"> 代码如下:<div class="codebody" id="code32230"> 聊天室 <?php $person = @$_POST[person]; $msg = @$_POST[message]; if ($person!="" && $msg!=""){ $handle = fopen("msg.txt","r"); $tot = 0; $oldmsg = array(); while ($content = fgets($handle)){ $oldmsg[] = $content; ++$tot; } fclose($handle); unlink("msg.txt"); $fp = fopen("msg.txt","a+"); $time = date("h:i"); fwrite($fp,"<font color="blue">".$person." in <font color="red">".$time."  says that  ".$msg." "."n"); for ($i =0;$i<$tot;++$i){ if ($i>50) break; fwrite($fp,$oldmsg[$i]); } } ?> <TABLE width="100%" border="0" cellspacing="0" cellpadding="0"> <tr align="left" bgcolor="#666666"> <td height="20"> </td></tr> <tr bgcolor="#FFCC66">
| </td> </tr>
|
<table width="100%" border=0 cellspacing=0 cellpadding=0 bgcolor="#EFEFEF">
<tr bgcolor="#666666">
<td align="left">
<table width="100%" height="500" boder=0 cellspacing=0 cellpadding=0 bgcolor="#EFEFEF">
<tr align="left">
<td valign="top">
<font size="-1" color="#666666"> <table width = "100%" border = "0">
<tr>
<form action="_a.php" method = "post">
<td align="left">
<font size="-1">昵称:
<input type="text" name="person" size="12" maxlength="80" value="<?php echo $person;?>">
<font size="-1">
<input type="submit" value="发言">
</td>
</tr>
</table>
</td>
</tr>
</tr>
</table>
</td>
</tr>
</table>
_b.php
<div class="codetitle">
<a style="CURSOR: pointer" data="10204" class="copybut" id="copybut10204" onclick="doCopy('code10204')"> 代码如下: <div class="codebody" id="code10204">
聊天室
<META HTTP-EQUIV=Refresh CONTENT="5; URL=_b.php">
<body bgcolor="#EFEFEF">
<?php
$handle=fopen("msg.txt","r");
//$oldmsg = array();
while ($content = fgets($handle)){
//$oldmsg[] = $content;
//++$tot;
echo $content;
}
?>