1.conn.php

<?php

/*
* PHP100Job v1.0
* Programmer : Msn/QQ
haowubai@hotmail.com (925939)
*
www.php100.com Develop a project PHP – MySQL – Apache
* Window 2003 – Preferences – PHPeclipse – PHP – Code Templates
*/

$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names ‘GBK’"); //使用GBK中文编码;

function htmtocode($content) {
$content = str_replace("\n", "<br>", str_replace(" ", "&nbsp;", $content));
return $content;
}

//$content=str_replace("’","‘",$content);
//htmlspecialchars();

?>

2.head.php

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<link href="images/css.css" rel="stylesheet" type="text/css">
<b><a href="add.php">添加留言</a> | <a href="list.php">浏览留言</a> | <a href="login.php">登陆</a> </b>
<hr size=1>
3.login.php

<?php
/*
* PHP100Job v1.0
* Programmer : Msn/QQ haowubai@hotmail.com (925939)
* www.php100.com Develop a project PHP – MySQL – Apache
* Window 2003 – Preferences – PHPeclipse – PHP – Code Templates
*/
include("conn.php");

if($_GET[out]){
setcookie("cookie", "out");
    echo "<script language=\"javascript\">location.href=’login.php';</script>";
}

if($_POST[id]==’admin’){
    $pw=md5($_POST[pw]);
    if($pw==’e1bfd762321e409cee4ac0b6e841963c’){
     setcookie("cookie", "ok");
       echo "<script language=\"javascript\">location.href=’login.php';</script>";
    }
}
include("head.php");
if($_COOKIE[‘cookie’]!=’ok’){
?>

<SCRIPT language=javascript>
function Checklogin()
{
if (myform.id.value=="")
{
   alert("请填写登录名");
   myform.id.focus();
   return false;
}
   if (myform.pw.value=="")
{
   alert("密码不能为空");
   myform.pw.focus();
   return false;
}
}
</SCRIPT>

<form action="" method="post" name="myform" onsubmit="return Checklogin();">
ID:<input type="text" name="id" /><br>
PW:<input type="password" name="pw" /> <input type="submit" name="submit" value="登陆"/>
</form>
<?
}else{
?>
<a href=’?out=login’>退出</a>
<?
}
?>

4.add.php

<?php
/*
* PHP100Job v1.0
* Programmer : Msn/QQ
haowubai@hotmail.com (925939)
*
www.php100.com Develop a project PHP – MySQL – Apache
* Window 2003 – Preferences – PHPeclipse – PHP – Code Templates
*/
include("conn.php");

if($_POST[‘submit’]){

$sql="insert into message (id,user,title,content,lastdate) " .
   "values (”,’$_POST[user]’,’$_POST[title]’,’$_POST[content]’,now())";
mysql_query($sql);
echo "<script language=\"javascript\">alert(‘添加成功’);history.go(-1)</script>";

}
include("head.php");
?>
<SCRIPT language=javascript>
function CheckPost()
{
if (myform.user.value=="")
{
   alert("请填写用户名");
   myform.user.focus();
   return false;
}
if (myform.title.value.length<5)
{
   alert("标题不能少于5个字符");
   myform.title.focus();
   return false;
}
if (myform.content.value=="")
{
   alert("必须要填写留言内容");
   myform.content.focus();
   return false;
}
}
</SCRIPT>

<form action="add.php" method="post" name="myform" onsubmit="return CheckPost();">
用户:<input type="text" size="10" name="user" /><br>
标题:<input type="text" name="title" /><br/>
内容:<textarea name="content" cols="60" rows="9"></textarea><br/>

<input type="submit" name="submit" value="发布留言"/>

</form>

5.list.php

<?php
/*
* PHP100Job v1.0
* Programmer : Msn/QQ haowubai@hotmail.com (925939)
* www.php100.com Develop a project PHP – MySQL – Apache
* Window 2003 – Preferences – PHPeclipse – PHP – Code Templates
*/
include("conn.php");

include("head.php");
$SQL="SELECT * FROM `message` order by id desc";
$query=mysql_query($SQL);
while($row=mysql_fetch_array($query)){
?>

<table width=500 border="0" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?
echo htmtocode($row[content]);
   ?></td>
</tr>
</table>
<?
}
?>