简单的网络聊天室

分为三块:

登陆界面,主界面,刷新界面,发送界面。

(1)登陆界面

<!--login.php-->
<html>
<head>
<title>uesr login</title>
</head>
<body>
	<center>
		<h1>welcom to chatting room</h1>
		<h2>input your nickname</h2>
		<form action="main.php" method="post" target="_self">
			<input type="text" name="nick" cols="20">
			<input type="submit" value="login">
		</from>
	</center>
</body>


</html>

(2)主界面

<?php
session_start();
// $user_name=
$_SESSION["user_name"]=$_POST["nick"];
?>
<!--chat.php-->
<html>
<title>chatting room</title>
<frameset rows="80%,*">
<frame src="chat_display.php" name="chat_display">
<frame src="speak.php" name="speak">
</frameset>

</html>
3(刷新界面)
<html>
<head>
<title>show user leave message</title>
<meta http-equiv="refresh" content="8;url=chat_display.php">
</head>
<body>
<?php
require_once("sys_conf.inc");

$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD) or die("connect failed" . mysql_error());
if(mysql_select_db($DBNAME)){
echo "database selecede";
}
else{

	echo "not select data base ";
}
$str="select * from  my_chatinfo order by create_time;";
$result=mysql_query($str,$link_id);
if($result)
$rows=mysql_num_rows($result);
else
{
	echo "no selcet!!".$result." resut" . mysql_error();
}
@mysql_data_seek($result, $rows-15);
if ($rows<15) {
	# code...
$l=$rows;
}else{$l=15;
}
for($i=1;$i<=$l;$i++){
   list($cid,$author,$create_time,$text)=mysql_fetch_row($result);
   echo $create_time;echo "[ ".$author."]";echo "say";
    echo $text;echo "<br>";
}
@mysql_data_seek($result,$rows-20);
list($limtime)=mysql_fetch_row($result);
$str="delete from my_chatinfo where create_time<'$limtime';";
mysql_query($str,$link_id);
mysql_close($link_id);

?>

</body>
</html>

(4)发言界面

<?php session_start();?>
<html>
<head>
<title>speak</title>
</head>
<body>
<?php
require_once("sys_conf.inc");

if ($_POST["text1"]) {
	$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
	mysql_select_db($DBNAME);
	$time=date("h;i;s");
	$text1=$_POST["text1"];
	$author=$_SESSION["user_name"];
	$str="insert into my_chatinfo
    (create_time,author,text) values('$time','$author','$text1');";
 mysql_query($str,$link_id);
 mysql_close();

  	# code...
}
?>
<form action="speak.php" method="post" target="_self">
<input type="text" name="text1" cols="20">
<input type="submit" value="send">
</form>



</body>
</html>

配置数据库的文件

<!--system configur-->
<?php
$DBHOST='localhost';
$DBUSER='root';
$DBPWD='';
$DBNAME='my_chat';
?>

主要学会了使用Php对数据库的操作,复习了html内容,熟悉了PHP基本语法。开发环境为xampp。

还缺少账号的验证,用户信息统计,注销等功能,下次完善,毕竟第一次。。。。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值