php寫的簡易聊天室代碼
更新時(shí)間:2011年06月04日 12:07:44 作者:
php寫的簡易聊天室代碼,需要的朋友可以參考下。
index.php
<html>
<head><Title>
在線聊天
</title></head>
<!-- frames -->
<frameset rows="70%,*" BORDER="0">
<frame name="top" src="_b.php" marginwidth="0" marginheight="0" scrolling="yes" FRAMEBORDER="NO" noresize>
<frame name="bottom" src="_a.php" marginwidth="0" marginheight="0" scrolling="no" frameborder="no" noresize>
</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> in <font color=\"red\">".$time."</font>  says that  <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="發(fā)言">
</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>
復(fù)制代碼 代碼如下:
<html>
<head><Title>
在線聊天
</title></head>
<!-- frames -->
<frameset rows="70%,*" BORDER="0">
<frame name="top" src="_b.php" marginwidth="0" marginheight="0" scrolling="yes" FRAMEBORDER="NO" noresize>
<frame name="bottom" src="_a.php" marginwidth="0" marginheight="0" scrolling="no" frameborder="no" noresize>
</frameset>
<body>
</body>
</html>
_a.php
復(fù)制代碼 代碼如下:
<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> in <font color=\"red\">".$time."</font>  says that  <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="發(fā)言">
</td>
</form>
</tr>
</table>
</font>
</td>
</tr>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
_b.php
復(fù)制代碼 代碼如下:
<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+websocket 實(shí)現(xiàn)的聊天室功能詳解
- php基于websocket搭建簡易聊天室實(shí)踐
- 基于Swoole實(shí)現(xiàn)PHP與websocket聊天室
- php+html5基于websocket實(shí)現(xiàn)聊天室的方法
- php socket實(shí)現(xiàn)的聊天室代碼分享
- PHP實(shí)現(xiàn)簡單聊天室(附源碼)
- 用PHP+MySQL搭建聊天室功能實(shí)例代碼
- 基于HTTP長連接的"服務(wù)器推"技術(shù)的php 簡易聊天室
- 如何用PHP websocket實(shí)現(xiàn)網(wǎng)頁實(shí)時(shí)聊天
相關(guān)文章
使用PHPStudy搭建Cloudreve網(wǎng)盤服務(wù)的流程步驟
自云存儲概念興起已經(jīng)有段時(shí)間了,各互聯(lián)網(wǎng)大廠也紛紛加入戰(zhàn)局,一時(shí)間公有云盤遍地開花,今天我們就為大家介紹,如何使用Cpolar與Cloudreve,在個(gè)人Windows電腦上搭建一個(gè)強(qiáng)大的PHP云盤系統(tǒng),需要的朋友可以參考下2024-02-02基于php實(shí)現(xiàn)七牛抓取遠(yuǎn)程圖片
由于公司網(wǎng)站之前的用戶頭像都是存儲在自己的服務(wù)器上的,后來感覺管理不方便,新增加的用戶頭像都上傳到了七牛,為了方便統(tǒng)一管理,領(lǐng)導(dǎo)說把本地服務(wù)器的頭像全部遷移到了七牛2015-12-12thinkPHP基于反射實(shí)現(xiàn)鉤子的方法分析
這篇文章主要介紹了thinkPHP基于反射實(shí)現(xiàn)鉤子的方法,結(jié)合實(shí)例形式分析了php基于系統(tǒng)自帶的ReflectionClass、ReflectionMethod 類與函數(shù)實(shí)現(xiàn)鉤子功能的相關(guān)操作技巧,需要的朋友可以參考下2017-11-11TP5框架實(shí)現(xiàn)一次選擇多張圖片并預(yù)覽的方法示例
這篇文章主要介紹了TP5框架實(shí)現(xiàn)一次選擇多張圖片并預(yù)覽的方法,結(jié)合實(shí)例形式詳細(xì)分析了thinkPHP5基于ajax數(shù)據(jù)提交上傳多張圖片與本地預(yù)覽相關(guān)操作技巧,需要的朋友可以參考下2020-04-04