php写的简易聊天室代码
程序员文章站
2024-02-15 10:51:22
...
index.php
在线聊天
_a.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,"".$person." in ".$time."  says that  ".$msg."
"."\n");
for ($i =0;$iif ($i>50) break;
fwrite($fp,$oldmsg[$i]);
}
}
?>
_b.php
聊天室
$handle=fopen("msg.txt","r");
//$oldmsg = array();
while ($content = fgets($handle)){
//$oldmsg[] = $content;
//++$tot;
echo $content;
}
?>
复制代码 代码如下:
在线聊天
_a.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,"".$person." in ".$time."  says that  ".$msg."
"."\n");
for ($i =0;$iif ($i>50) break;
fwrite($fp,$oldmsg[$i]);
}
}
?>
|
|
_b.php
复制代码 代码如下:
聊天室
$handle=fopen("msg.txt","r");
//$oldmsg = array();
while ($content = fgets($handle)){
//$oldmsg[] = $content;
//++$tot;
echo $content;
}
?>
上一篇: 堆的简单实现