欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php写的简易聊天室代码

程序员文章站 2024-02-15 10:51:22
...
index.php

复制代码 代码如下:



<br>在线聊天 <br>









_a.php

复制代码 代码如下:



<br>聊天室 <br>

$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."&nbspin&nbsp".$time."&nbsp&nbspsays that&nbsp&nbsp".$msg."
"."\n");
for ($i =0;$iif ($i>50) break;
fwrite($fp,$oldmsg[$i]);
}
}
?>




























昵称:













_b.php

复制代码 代码如下:




<br>聊天室 <br>



$handle=fopen("msg.txt","r");
//$oldmsg = array();
while ($content = fgets($handle)){
//$oldmsg[] = $content;
//++$tot;
echo $content;
}
?>