仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1477|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网站制作之php写的简略单纯聊天室代码

[复制链接]
小魔女 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-16 00:23:12 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
PHP于1994年由Rasmus Lerdorf创建,刚刚开始是Rasmus Lerdorf为了要维护个人网页而制作的一个简单的用Perl语言编写的程序。   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>&nbspin&nbsp<font color=\"red\">".$time."</font>&nbsp&nbspsays that&nbsp&nbsp<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>


模仿的不光是模仿,模仿的同时在加改进,就成了自己的作品了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-17 21:33

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表