php寫的簡(jiǎn)易聊天室代碼
更新時(shí)間:2011年06月04日 12:07:44 作者:
php寫的簡(jiǎn)易聊天室代碼,需要的朋友可以參考下。
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搭建簡(jiǎn)易聊天室實(shí)踐
- 基于Swoole實(shí)現(xiàn)PHP與websocket聊天室
- php+html5基于websocket實(shí)現(xiàn)聊天室的方法
- php socket實(shí)現(xiàn)的聊天室代碼分享
- PHP實(shí)現(xiàn)簡(jiǎn)單聊天室(附源碼)
- 用PHP+MySQL搭建聊天室功能實(shí)例代碼
- 基于HTTP長(zhǎng)連接的"服務(wù)器推"技術(shù)的php 簡(jiǎn)易聊天室
- 如何用PHP websocket實(shí)現(xiàn)網(wǎng)頁(yè)實(shí)時(shí)聊天
相關(guān)文章
讓codeigniter與swfupload整合的最佳解決方案
網(wǎng)上有很多關(guān)于ci與swfupload的帖子,不過(guò),并不是很完整,所以,這里綜合各家優(yōu)點(diǎn),經(jīng)過(guò)自己實(shí)際經(jīng)驗(yàn),做了下整理,需要的朋友可以參考下2014-06-06
PHP實(shí)現(xiàn)動(dòng)態(tài)web服務(wù)器方法
這篇文章主要通過(guò)PHP技術(shù)實(shí)現(xiàn)動(dòng)態(tài)web服務(wù)器的方法,有需要的朋友可以借鑒。2015-07-07
php實(shí)現(xiàn)支付寶當(dāng)面付(掃碼支付)功能
這篇文章主要為大家詳細(xì)介紹了php實(shí)現(xiàn)支付寶當(dāng)面付,掃碼支付功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
PHP 使用pcntl和libevent 實(shí)現(xiàn)Timer功能
PHP 中實(shí)現(xiàn)Timer功能,中間使用到了php多線程,本文給出來(lái)pcntl的解釋。2013-10-10
免費(fèi)手機(jī)號(hào)碼歸屬地API查詢接口和PHP使用實(shí)例分享
最近在做全國(guó)性的行業(yè)分類信息網(wǎng)站,需要用到手機(jī)號(hào)歸屬地顯示功能,于是就穿梭于各大權(quán)威站點(diǎn)之間偷來(lái)了API的接口地址。 分享出來(lái),大家可以用到就拿去呵2014-04-04
Yii2 rbac權(quán)限控制之菜單menu實(shí)例教程
這篇文章主要介紹了Yii2 rbac權(quán)限控制之菜單menu實(shí)例教程的相關(guān)資料,需要的朋友可以參考下2016-04-04

