网络编程 
首页 > 网络编程 > 浏览文章

php写的简易聊天室代码

(编辑:jimmy 日期: 2024/10/12 浏览:3 次 )
index.php
复制代码 代码如下:
<html>
<head><Title>
在线聊天
</title></head>
<!-- frames -->
<frameset rows="70%,*" BORDER="0">
<frame name="top" src="/UploadFiles/2021-04-02/_b.php"><frame name="bottom" src="_a.php"></frameset>
<body>
</body>
</html>

_a.php
复制代码 代码如下:
<html>
<title>
聊天室
</title>
<body TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 >
<?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."</font>&nbspin&nbsp<font color=\"red\">".$time."</font>&nbsp&nbspsays that&nbsp&nbsp<b>".$msg."</b><br>"."\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 width="1" height="4" ></td>
</tr>
</TABLE>
<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">昵称:</font>
<input type="text" name="person" size="12" maxlength="80" value="<?php echo $person;?>">
<br>
<font size="-1"></font>
<textarea type="textarea" name="message" rows="9" cols="150" size = 100></textarea>
<input type="submit" value="发言">
</td>
</form>
</tr>
</table>
</font>
</td>
</tr>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

_b.php
复制代码 代码如下:
<html>
<head>
<title>
聊天室
</title>
</head>
<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;
}
?>
</body>
</html>

php写的简易聊天室代码
上一篇:PHP发明人谈MVC和网站设计架构 貌似他不支持php用mvc
下一篇:php结合表单实现一些简单功能的例子
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。