分为三块:
登陆界面,主界面,刷新界面,发送界面。
(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。
还缺少账号的验证,用户信息统计,注销等功能,下次完善,毕竟第一次。。。。