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 相关文章推荐
打造计数器DIY三步曲(中)
Oct 09 PHP
PHP文本操作类
Nov 25 PHP
实用函数2
Nov 08 PHP
php cout&amp;lt;&amp;lt;的一点看法
Jan 24 PHP
php表单提交问题的解决方法
Apr 12 PHP
php stripslashes和addslashes的区别
Feb 03 PHP
php中error与exception的区别及应用
Jul 28 PHP
基于JQuery+PHP编写砸金蛋中奖程序
Sep 08 PHP
浅谈php中urlencode与rawurlencode的区别
Sep 05 PHP
PHP定义字符串的四种方式详解
Feb 06 PHP
php 读写json文件及修改json的方法
Mar 07 PHP
PHP实现登录验证码校验功能
May 17 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
一棵php的类树(支持无限分类)
2006/10/09 PHP
十天学会php之第三天
2006/10/09 PHP
php 无法加载mysql的module的时候的配置的解决方案引发的思考
2012/01/27 PHP
Yii2中使用join、joinwith多表关联查询
2016/06/30 PHP
PHP笛卡尔积实现原理及代码实例
2020/12/09 PHP
基于jQuery实现的Ajax 验证用户名是否存在的实现代码
2011/04/06 Javascript
40款非常有用的 jQuery 插件推荐(系列一)
2011/12/21 Javascript
js的正则test,match,exec详细解析
2014/01/29 Javascript
javaScript的函数对象的声明详解
2015/02/06 Javascript
js代码实现随机颜色的小方块
2015/07/30 Javascript
javaScript事件学习小结(四)event的公共成员(属性和方法)
2016/06/09 Javascript
canvas滤镜效果实现代码
2017/02/06 Javascript
微信小程序中子页面向父页面传值实例详解
2017/03/20 Javascript
AngularJS 仿微信图片手势缩放的实例
2017/09/28 Javascript
json前后端数据交互相关代码
2018/09/19 Javascript
Vue开发之封装分页组件与使用示例
2019/04/25 Javascript
微信小程序开发中var that =this的用法详解
2020/01/18 Javascript
Vue如何使用混合Mixins和插件开发详解
2020/02/05 Javascript
[02:15]2014DOTA2国际邀请赛 赛后退役选手回顾
2014/08/01 DOTA
Python2.7下安装Scrapy框架步骤教程
2017/12/22 Python
python机器学习理论与实战(四)逻辑回归
2018/01/19 Python
Django重装mysql后启动报错:No module named ‘MySQLdb’的解决方法
2018/04/22 Python
浅谈python中真正关闭socket的方法
2018/12/18 Python
pandas数据集的端到端处理
2019/02/18 Python
python模拟实现斗地主发牌
2020/01/07 Python
使用tensorflow实现矩阵分解方式
2020/02/07 Python
Python logging日志库空间不足问题解决
2020/09/14 Python
pycharm如何设置官方中文(如何汉化)
2020/12/29 Python
美国求婚钻戒网站:Super Jeweler
2016/08/27 全球购物
放飞中国梦演讲稿
2014/04/23 职场文书
书法兴趣小组活动总结
2014/07/07 职场文书
淘宝客服专员岗位职责
2015/04/07 职场文书
原告代理词范文
2015/05/25 职场文书
圣贤教育改变命运观后感
2015/06/16 职场文书
nginx前后端同域名配置的方法实现
2021/03/31 Servers
goland设置颜色和字体的操作
2021/05/05 Golang