PHP 基于文本系统的简易的聊天室

login.php

<html>
<body bgcolor="#CCCCCC">
<center>聊天室</center>
<hr width="60%" />
<form action="chat.php">
<center>
<table>
<tr><td>
选择房间:<select name="room">
				<option value="大厅">大厅</option>
				<option value="客房">客房</option>
				<option value="后院">后院</option>
		  </select>
</td></tr>
<tr><td>
你的名称:<input type="text" name="name" />
<input type="submit" value="进入" />
</td></tr>
</table>
<hr width="60%" />
</center>
</form>
</body>
</html>

input.php

<html>
<head>
<meta http-equiv="refresh" content="url=input.php?color=<?php echo $color;?>" />
<title>聊天室</title>
</head>
<body bgcolor="#CCCCCC" topmargin="0">

<?php

$name=str_replace("<","<",$name);
$name=str_replace("<",">",$name);
$name=stripslashes(trim($name));
?>

<table border="0">
<form action="input.php" method="post">
<tr>
<td>
位置:<font color="#0000FF"><? echo $room;?></font>
<input type="hidden" name="room" value="<? echo $room;?>" />
名称:<font color="#0000FF"><? echo $name;?></font>
您的表情:
<select name="say">
	<option value="说">无所谓</option>
	<option value="毫无表情地说">毫无表情</option>
	<option value="高兴地说">高兴</option>
	<option value="惊奇地说">惊奇</option>
	<option value="气愤地说">气愤</option>
</select>
选择颜色:
<select name="color">
	<option value="#FFFFFF">白</option>
	<option value="#FF0000">红</option>
	<option value="#FFFF00">黄</option>
	<option value="#0000FF">蓝</option>
	<option value="#800080">紫</option>
	<option value="#008000">绿</option>
	<option value="#00CC00">青</option>
</select>
 </td></tr>
 <tr><td>
 <input type="hidden" name="name" value="<? echo $name;?>" />
 内容:<input type="text" name="message" size="75" />
 <input type="submit" value="确定" />
 </td></tr></form>
 <?
 	date_default_timezone_set('Asia/Shanghai');
 	$t=date(d日H时i分);
	$talk=100;
	$r=25;
	switch($room){
		case '大厅':
			$write_file="1.txt";
			break;
		case '客房':
			$write_file="2.txt";
			break;
		case '后院':
			$write_file="3.txt";
			break;
		default:
			$write_file="0.txt";
			break;
	}
	$max_file_size=$r*($talk+15);
	$file_size=filesize($chat_file);
	
	if($file_size>$max_file_size){
		
		$lines=file($write_file);
		$tmp=count($lines);
		$u=$tmp-$r;
		for($i=$tmp;$i>=$u;$i--){
			$msg_old=$lines[$i].$msg_old;
		}
		$deleted=unlink($wirte_file);
		$fp=fopen($write_file,"a+");
		$fw=fwrite($fp,$msg_old);
		fclose($fp);
	}
	
	$msg=str_replace("\n"," ",$message);
	$msg=str_replace("<","<",$msg);
	$msg=str_replace("<",">",$msg);
	$msg=stripslashes($msg);
	
	if($msg!=""){
		$fp=fopen($write_file,"a+");
		$fw=fwrite($fp,"\n <font color=$color><b>[$t]$name$say:</b>$msg</font>");
		fclose($fp);
	}
?>
</table>
</body>
</html>

view.php

<html>
<meta http-equiv="refresh" content="5;url=view.php?room=<?php echo $room;?>" />
<body bgcolor="#000000">
<?
	switch($room){
		case '大厅':
			$write_file="1.txt";
			break;
		case '客房':
			$write_file="2.txt";
			break;
		case '后院':
			$write_file="3.txt";
			break;
		default:
			$write_file="0.txt";
			break;
	}
	$chat_length=25;
	$lines=file($write_file);
	$a=count($lines);
	$u=$a-$chat_length;
	for($i=$a;$i>=$u;$i--){
		echo $lines[$i]."<br>";
	}
?>
</body>
</html>

chat.php

<html>
<head>
<title>聊天室</title>
</head>
<frameset rows="80%,*" cols="*">
	<frame src="view.php?room=<?php echo $room;?>" />
	<frame src="input.php?name=<?php echo $name;?>&room=<?php echo $room;?>" />
</frameset>
<noframes>
<body bgcolor="#CCCCCC">
</body>
</noframes>
</html>







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值