php写的简易聊天室代码


Posted in PHP onJune 04, 2011

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="发言"> 
</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>

php写的简易聊天室代码
PHP 相关文章推荐
PHP4在WinXP下IIS和Apache2服务器上的安装实例
Oct 09 PHP
开源SNS系统-ThinkSNS
May 18 PHP
PHP strtotime函数详解
Dec 18 PHP
一步一步学习PHP(7) php 字符串相关应用
Mar 05 PHP
php HtmlReplace输入过滤安全函数
Jul 03 PHP
PHP网站备份程序代码分享
Jun 10 PHP
PHP句法规则详解 入门学习
Nov 09 PHP
php操作mysql数据库的基本类代码
Feb 25 PHP
PHP批量检测并去除文件BOM头代码实例
May 08 PHP
php微信公众平台开发(一) 配置接口
Dec 06 PHP
记Laravel调用Gin接口调用formData上传文件的实现方法
Dec 12 PHP
浅析PHP反序列化中过滤函数使用不当导致的对象注入问题
Feb 15 PHP
php结合表单实现一些简单功能的例子
Jun 04 #PHP
PHP中对用户身份认证实现两种方法
Jun 04 #PHP
关于php curl获取301或302转向的网址问题的解决方法
Jun 02 #PHP
基于PHP的cURL快速入门教程 (小偷采集程序)
Jun 02 #PHP
PHP curl_setopt()函数实例代码与参数分析
Jun 02 #PHP
php小技巧 把数组的键和值交换形成了新的数组,查找值取得键
Jun 02 #PHP
使ecshop模板中可引用常量的实现方法
Jun 02 #PHP
You might like
《DOTA3》开发工作已经开始 《DOTA3》将代替《DOTA2》
2021/03/06 DOTA
PHP输出数组中重名的元素的几种处理方法
2012/09/05 PHP
php 判断是否是中文/英文/数字示例代码
2013/09/30 PHP
浅析echo(),print(),print_r(),return之间的区别
2013/11/27 PHP
老生常谈php 正则中的i,m,s,x,e分别表示什么
2017/03/02 PHP
从sohu弄下来的flash中展示图片的代码
2007/04/27 Javascript
juqery 学习之三 选择器 层级 基本
2010/11/25 Javascript
对javascript的一点点认识总结《javascript高级程序设计》读书笔记
2011/11/30 Javascript
jQuery方法简洁实现隔行换色及toggleClass的使用
2013/03/15 Javascript
Js使用WScript.Shell对象执行.bat文件和cmd命令
2014/12/18 Javascript
JavaScript数组随机排列实现随机洗牌功能
2015/03/19 Javascript
jQuery实现提交按钮点击后变成正在处理字样并禁止点击的方法
2015/03/24 Javascript
Hallo.js基于jQuery UI所见即所得的Web编辑器
2016/01/26 Javascript
简单的分页代码js实现
2016/05/17 Javascript
对jQuary选择器的全面总结
2016/06/20 Javascript
Bootstrap复选框和单选按钮美化插件(推荐)
2016/11/23 Javascript
JQuery获取鼠标进入和离开容器的方向
2016/12/29 Javascript
利用nvm管理多个版本的node.js与npm详解
2017/11/02 Javascript
理解Koa2中的async&amp;await的用法
2018/02/05 Javascript
python通过urllib2爬网页上种子下载示例
2014/02/24 Python
Python中splitlines()方法的使用简介
2015/05/20 Python
django框架基于模板 生成 excel(xls) 文件操作示例
2019/06/19 Python
TensorFlow-gpu和opencv安装详细教程
2020/06/30 Python
Python批量修改xml的坐标值全部转为整数的实例代码
2020/11/26 Python
美国体育用品在线:Modell’s Sporting Goods
2018/06/07 全球购物
美国单身专业人士在线约会网站:EliteSingles
2019/03/19 全球购物
世界各地的当地人的食物体验:Eatwith
2019/07/26 全球购物
车贷收入证明范本
2014/01/09 职场文书
党员贯彻十八大精神思想汇报范文
2014/10/25 职场文书
放假通知怎么写
2015/08/18 职场文书
人事任命书范本
2015/09/21 职场文书
高三数学教学反思
2016/02/18 职场文书
Pytorch实现图像识别之数字识别(附详细注释)
2021/05/11 Python
MySQL分区表实现按月份归类
2021/11/01 MySQL
CSS实现切角+边框+投影+内容背景色渐变效果
2021/11/01 HTML / CSS
基于PostgreSQL/openGauss 的分布式数据库解决方案
2021/12/06 PostgreSQL