Home  >  Article  >  Backend Development  >  Simple chat room code written in php_PHP tutorial

Simple chat room code written in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:29:31657browse

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." in ".$time."  says that  ".$msg."
"."n");
for ($i =0;$i<$tot;++$i){
if ($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;
}
?>



Simple chat room code written in php_PHP tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323403.htmlTechArticleindex.php Copy the code as follows: html headTitle online chat/title/head !-- frames -- frameset rows ="70%,*" BORDER="0" frame name="top" src="_b.php" marginwidth="0" marginheigh...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn