好了,其它的都快完了我们就来看看index.php文件显示留方的页面吧.
<?php
@session_start();
include("global.php");
if(isset($_GET['act']) && $_GET['act'] == 'del')
{
if(isset($_GET['mid']))
{
$mid = intval($_GET['mid']);
if(mysql_query("DELETE FROM xx_guestbook WHERE mid={$mid}"))
{
echo("delete OK!");
die("<script>window.location.href='{$_SERVER['PHP_SELF']}';</script>");
//echo "<meta http-equiv=\"refresh\" content=\"1; url=index.php\">";
}
else echo("false");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>求职留言本</title>
<style type="text/css">
<!--
body {
background: #C7EDDD;
text-align: center;
margin: 0px;
padding: 0px;
font-size: 12px;
}
a {
text-decoration: none;
margin: 0px;
padding: 0px;
}
.messagebox img {
margin: 0px;
padding: 0px;
}
.all {
margin: 0px auto;
padding: 0px 0px 10px;
width: 780px;
background: #C7EDCC;
text-align: left;
}
.header {
margin: 0px;
padding: 0px;
height: 90px;
background: #DDDDDD;
border-top: 5px solid #660066;
border-right: 1px solid #660066;
border-bottom: 1px solid #660066;
border-left: 1px solid #660066;
}
.header h1 {
font-size: 36px;
font-weight: bold;
margin: 0px;
padding: 5px 10px 0px;
}
.header #menu {
margin: 0px;
padding: 25px 10px 0px;
height: 20px;
font-size: 14px;
font-weight: bold;
text-align: right;
}
.messagebox {
margin: 20px 10px 0px;
padding: 0px 0px 5px;
width: 760px;
border: 1px solid #33FFFF;
background: #C7EDCC;
}
.messagebox a {
text-decoration: none;
margin: 0px;
padding: 0px;
}
.messagebox-top {
border-bottom: 1px dashed #00FFFF;
margin: 0px;
padding: 3px 0px 0px;
height: 20px;
background: #CCFFFF;
}
.messagebox-topl {
margin: 0px 0px 0px 10px;
padding: 0px;
float: left;
}
.messagebox-topr {
margin: 0px 5px 0px 0px;
padding: 0px;
float: right;
}
.messagebox-topc {
margin: 1px;
padding: 0px 20px;
}
.messagebox-show {
margin: 5px 10px 0px;
padding: 3px 3px 5px;
overflow: hidden;
border: 1px solid #00FFCC;
}
.messagebox-reply {
border-top: 1px dashed #00FFCC;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-style: dashed;
border-bottom-style: dashed;
border-left-style: dashed;
margin: 2px 10px 0px;
padding: 2px 2px 5px;
background: #E0EDDC;
}
.messagebox-replyt {
font-weight: bold;
color: #0000FF;
margin: 0px 0px 5px;
padding: 0px;
}
.pages {
background: #00FFFF;
margin: 5px 20px 0px;
padding: 0px 0px 5px;
}
.foot {
background: #E0EDDC;
margin: 5px 0px 0px;
padding: 5px;
text-align: center;
}
-->
</style>
</head>
<body>
<div class="all">
<div class="header">
<h1>求职留言本</h1>
<div id="menu"><a href="index.php">首页</a> <a href="madd.php">发表留言</a><?php
if(!$_SESSION[user])
echo "<a href=\"login.php\">登陆</a>";
if($_SESSION[user])
echo "<a href=\"logout.php\">退出</a>";
?>
</div>
<!-- menu -->
</div><!-- header -->
<?php
$page = isset($_GET['page'])?intval($_GET['page']):1;
$num=10;
$total=mysql_num_rows(mysql_query("select * from xx_guestbook"));
$pagenum=ceil($total/$num);
if($page>$pagenum || $page<=0 || empty($page))
{
//header("location:index.php?page=1"); DEBUG
$page = 1;
}
$offset=($page-1)*$num;
$sql = "SELECT * FROM xx_guestbook ORDER BY posttime DESC LIMIT {$offset},{$num}";
$query = mysql_query($sql);
while($info = mysql_fetch_array($query))
{
?>
<div class="messagebox">
<div class="messagebox-top"><span class="messagebox-topl"><strong><a href="#"><a href="#"><?php echo("{$info['username']}"); ?> </a></strong>发表于 <?php echo("{$info['posttime']}"); ?></span> <span class="messagebox-topr"><a href="#"><img src="images/city.gif" alt="IP:<?php echo("{$info['ip']}"); ?>" /></a> <a href="mailto:<?php echo("{$info['email']}"); ?>"><img src="images/email2.gif" alt="给TA发email:<?php echo("{$info['email']}"); ?>" /></a> <a href="tencent://message/?uin=<?php echo("{$info['oicq']}"); ?>&Site=web&Menu=yes"><img src="images/qq.gif" alt="QQ:<?php echo("{$info['oicq']}"); ?>" /></a> <a href="<?php echo("{$info['weburl']}"); ?>" target="_blank"><img src="images/web.gif" alt="主页:<?php echo("{$info['weburl']}"); ?>" /></a></span>
<?php
if($_SESSION[user])
{
?>
<span class="messagebox-topc"><strong><a href="mreply.php?act=edit&mid=<?php echo("{$info['mid']}"); ?>">编辑回复</a> <a onclick="var r=confirm("确认删除吗?")
if (r==true)
{
window.location.href='<?php $_SERVER['PHP_SELF']; ?>?act=del&mid=<?php echo("{$info['mid']}"); ?>';
}
else
{
window.location.href='<?php $_SERVER['PHP_SELF']; ?>';
}" href="#">删除</a></strong></span>
<?php
}
?>
</div>
<!-- messagebox-top -->
<div class="messagebox-show"><?php echo("{$info['content']}"); ?></div>
<!-- messagebox-show -->
<?php
if(!empty($info['reply']))
{
?>
<div class="messagebox-reply">
<div class="messagebox-replyt">admin回复于:<?php echo("{$info['replytime']}"); ?></div>
<?php echo("{$info['reply']}"); ?></div>
<?php
}
?>
<!-- messagebox-reply -->
</div>
<!-- messagebox -->
<?php
}
$prepage = $page - 1;
$nextpage = $page + 1;
?>
<div class="pages">共 <strong><?php echo("$pagenum"); ?></strong> 页 当前第 <strong><?php echo("$page"); ?></strong> 页 <a href="index.php?page=1">第一页</a> <a href="index.php?page=<?php echo("$prepage"); ?>">上一页</a> <a href="index.php?page=<?php echo("$nextpage"); ?>">下一页</a> <a href="index.php?page=<?php echo("$pagenum"); ?>">最后一页</a> </div><!-- pages -->
<div class="foot">
菜根 <br />
Copyright © 菜根 xanxin <a href="http://phpvc.com">http://phpvc.com</a> </div>
<!-- foot -->
</div>
<!-- all -->
</body>
</html>
显示了当然会有留言页面喽,如下.
<?php
@session_start();
include("global.php");
//获得IP地址 来自sablogX 1.6
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$onlineip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$onlineip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$onlineip = $_SERVER['REMOTE_ADDR'];
}
$onlineip = addslashes($onlineip);
if($_POST['add'] == 'add')
{
$username = $_POST['username'];
$username = htmlspecialchars($username);
$username = trim($username);
$qq = $_POST['qq'];
$email = $_POST['email'];
$email = htmlspecialchars($email);
$weburl = $_POST['weburl'];
$weburl = htmlspecialchars($weburl);
$content = $_POST['content'];
$ip = $onlineip;//$_SERVER['REMOTE_ADDR'];
$posttime = date('Y-m-d H:i:s');
$content = htmlspecialchars($content);
$content = str_replace(""," ",$content);
$content = str_replace(" "," ",$content);
$content = str_replace("\n","<br />",$content);
$sql = "INSERT INTO xx_guestbook(username,email,weburl,oicq,content,posttime,ip) VALUES('$username','$email','$weburl','$qq','$content','$posttime','$ip')";
if(mysql_query($sql))
{
echo("post OK!");
die("<script>window.location.href='lyb.php';</script>");
//echo "<meta http-equiv=\"refresh\" content=\"1; url=index2.php\">";
}
else
{
echo"false!";
}
}
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>发表留言</title>
<style type="text/css">
<!--
body {
font-size: 12px;
background: #FAFCFF;
}
-->
</style>
<script language=JavaScript>
function FrontPage_Form1_Validator(theForm)
{
if (theForm.username.value == "")
{
alert("请填写昵称!");
history.back();
theForm.username.focus();
return (false);
}
if (theForm.username.value.length<3)
{
alert("昵称至少应为3个字符!");
theForm.username.focus();
return (false);
}
if (theForm.username.value.length>15)
{
alert("昵称不能大于15个字符!");
theForm.username.focus();
return (false);
}
if(theForm.email.value!=""){
var email1 = theForm.email.value;
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
flag = pattern.test(email1);
if(!flag){
alert("邮件地址格式不对!");
theForm.email.focus();
return false;
}
}
if(theForm.qq.value!="")
{
for (i=1;i<theForm.qq.value.length;i++){
ct=theForm.qq.value.charAt(i);
if (!(ct>='0'&&ct<='9'))
{
alert("QQ号码只允许输入0-9数字");
theForm.qq.focus();
return(false);
}
}
}
if (theForm.content.value == "")
{
alert("留言内容不能空!");
theForm.content.focus();
return (false);
}
if (theForm.content.value.length<5)
{
alert("留言内容最少5个字符!");
theForm.content.focus();
return (false);
}
if (theForm.weburl.value != "")
{
var weburl = theForm.weburl.value;
var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-.\/?%&=]*)?/;
var objExp = new RegExp(Expression);
if(objExp.test(weburl) != true)
{
alert("url地址格式不对!");
theForm.weburl.focus();
return false;
}
}
return (true);
}
</script>
</head>
<body>
<table width="681" border="0" cellspacing="0" cellpadding="0" align="center">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="message" id="message" onsubmit="return FrontPage_Form1_Validator(this)">
<tr>
<td height="25" colspan="2" align="center"><strong>发表留言(带*为必填)</strong></td>
</tr>
<tr>
<td width="109" height="25" align="right">呢称: </td>
<td width="572" height="25"><label>
<input name="username" type="text" class="input" id="username" value="<?php
if($_SESSION[user])
echo "{$_SESSION[user]}";
?>" />
<font color="#000000">*</font>(<font color="#ff6600">*</font>为必填项)</label></td>
</tr>
<tr>
<td height="25" align="right">QQ: </td>
<td height="25"><label>
<input name="qq" type="text" class="input" id="qq" />
(纯数字)</label></td>
</tr>
<tr>
<td height="25" align="right">E-mail: </td>
<td height="25"><label>
<input name="email" type="text" class="input" id="email" size="30" />
(必须含有@)</label></td>
</tr>
<tr>
<td height="25" align="right">个人主页(blog): </td>
<td height="25"><label>
<input name="weburl" type="text" class="input" id="weburl" size="30" />
(以http://开关)</label></td>
</tr>
<tr>
<td height="25" align="right">内容: </td>
<td height="25"><label>
<textarea name="content" cols="70" rows="15" class="input" id="content"></textarea>
<font color="#000000">*</font></label></td>
</tr>
<tr>
<td height="25"> </td>
<td height="25"><label>
<input name="submit" type="submit" class="botton" id="submit" value="发表留言" />
<input name="reset" type="reset" class="botton" value="重新填写" id="reset" />
<input name="add" type="hidden" id="add" value="add" />
</label></td>
</tr>
</form>
</table>
</body>
</html>
<?php
}
?>
OK了简单的留言系统就OK了.