Web开发-简单BBS论坛

4 篇文章 0 订阅
1 篇文章 0 订阅

Web开发-简单BBS论坛

开发了两周的bbs论坛系统,总算在上周完成了,并且已经把项目文件上传到github上了。[我的bbs]。。。

开发完之后,感觉对sql语句、mysql函数和PHP代码有了深刻的理解。同时了解了开发流程。。好像收获很多耶!!!总结一下吧。。。

大致思路

需求

  1. 浏览者有浏览任何版块、任何帖子以及任何回复的权限,并且任何浏览者都有注册成为本论坛的用户的权限。
  2. 注册用户比浏览者多了发帖,回复帖子的权限,且具有成为某子版块版主的机会
  3. 版主比注册用户多出删除本版块帖子和相关回复的权限
  4. 管理员具有操作网站后台的权限(比如设置版块、更改站点信息、帖子管理、用户管理等)

功能

在这里插入图片描述

数据库设计

*1、数据库名称:*bbs

2、数据表:

(1)father_module父版块表 字段:id、module_name、sort

(2)son_module子版块表 字段:id、father_module_id、module_name、info、member_id、sort

(3)member会员表 字段:id、username、password、photo、register_name、last_time

(4)content帖子表 字段:id、module_id、title、content、time、member_id、times

(5)reply帖子回复表 字段:id、content_id、quote_id、content、time、member_id

(6)manage管理员表 字段:id、username、password

(7) info站点信息 字段:id、title、keywords、description

程序目录结构

admin/:存放后台程序文件

inc/:存放被包含的文件

style/:存放样式、图片 (后台我使用的是css\、fonts\和images。存放样式、图片)

uploads/:存放上传文件

其他各种文件

开发步骤

  1. 前台与后台的界面
  2. 后台-父版块
  3. 后台-子版块
  4. 前台-用户注册
  5. 前台-用户发帖
  6. 前台-帖子列表页
  7. 前台-帖子内容页
  8. 前台-帖子回复
  9. 前台-首页
  10. 前台-用户中心

等等…

开发步骤实现

准备

因为写总结时,功能已经实现。所以把开发过程中的一些准备,直接都写出来了。

mysql函数库

在与admin同级目录inc/里创建一个php文件名为mysql.inc.php。并在文件里写入相关mysql函数。代码【mysql.inc.php

相关设置

同样在与admin同级目录inc/里创建一个php文件名为config.inc.php。里面包括设置时区、开启session、转换编码、设置数据库连接信息和找到绝对路径。代码如下:

<?php 
date_default_timezone_set('Asia/Shanghai');//设置时区
session_start();
header('Content-type:text/html;charset=utf-8');
define('DB_HOST','localhost');
define('DB_USER','root');
define('DB_PASSWORD','密码');
define('DB_DATABASE','bbs');
define('DB_PORT',3306);
//项目(程序),在服务器上的绝对路径
define('SA_PATH',dirname(dirname(__FILE__)));
//项目在web根目录下面的位置(哪个目录里面)
define('SUB_URL',str_replace($_SERVER['DOCUMENT_ROOT'],'',str_replace('\\','/',SA_PATH)).'/');
?>
跳转和登录验证

直接跳转,执行结果信息不太明确。可以设置跳转结果显示。如图:
在这里插入图片描述

于是把该功能写在了php文件tool.inc.php。该文件中也写了会员是否登录验证和管理员是否登录的验证。

代码【tool.inc.php

后台相关验证

为了方便,我将admin目录里的inc/目录里的相关验证写在下面

1.check_father_module.inc.php

2.check_login.inc.php

3.check_manage.inc.php

4.check_son_module.inc.php

5.is_manage_login.inc.php

相关代码

后台删除确认页confirm.php

代码地址

一、前台与后台的界面

前台和后台界面可以自己用html和css写,也可以找一些模板。我为了方便,于是找了模板。。。。毕竟是主要为了练习php和sql语句以及mysql函数。

前台界面模板

在这里插入图片描述

后台界面模板

在这里插入图片描述

后台界面有点不合适,于是把顶部、底部和左侧写在不同文件,把后台界面修改了一下

header.inc.php、sidebar.inc.php和footer.inc.php(都在admin目录里的inc目录里)

//header.inc.php
<?php
$query="select * from info where id=1";
$result_info=execute($link, $query);
$data_info=mysqli_fetch_assoc($result_info);
?>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><?php echo $template['title'] ?> - <?php echo $data_info['title']?></title>
	<meta name="keywords" content="<?php echo $data_info['keywords']?>" />
	<meta name="description" content="<?php echo $data_info['description']?>" />
    <link rel="stylesheet" type="text/css" href="css/common.css"/>
    <link rel="stylesheet" type="text/css" href="css/main.css"/>
</head>
<body>
<div class="topbar-wrap white">
    <div class="topbar-inner clearfix">
        <div class="topbar-logo-wrap clearfix">
            <h1 class="topbar-logo none"><a href="index.html" class="navbar-brand">后台管理</a></h1>
            <ul class="navbar-list clearfix">
                <li><a class="on" href="login.html">后台首页</a></li>
                <li><a href="../index.php" target="_blank">网站首页</a></li>
            </ul>
        </div>
        <div class="top-info-wrap">
            <ul class="top-info-list clearfix">
                <li>管理员<?php echo $_SESSION['manage']['username']?></li>
                <li><a href="logout.php">注销</a></li>
            </ul>
        </div>
    </div>
</div>
//sidebar.inc.php
<div class="container clearfix">
    <div class="sidebar-wrap">
        <div class="sidebar-title">
            <h1>菜单</h1>
        </div>
        <div class="sidebar-content">
            <ul class="sidebar-list">
                <li>
                    <a href="#"><i class="icon-font">&#xe018;</i>系统</a>
                    <ul class="sub-menu">
                        <li><a href="index.php"><i class="icon-font">&#xe017;</i>系统信息</a></li>
                        <li><a href="manage.php"><i class="icon-font">&#xe014;</i>管理员</a></li>
                        <li><a href="manage_add.php"><i class="icon-font">&#xe068;</i>添加管理员</a></li>
                        <li><a href="system.php"><i class="icon-font">&#xe002;</i>站点设置</a></li>
                    </ul>
                </li>
                <li>
                    <a href="#"><i class="icon-font">&#xe009;</i>内容管理</a>
                    <ul class="sub-menu">
                        <li><a href="father_module.php"><i class="icon-font">&#xe006;</i>父版块列表</a></li>
                        <li><a href="father_module_add.php"><i class="icon-font">&#xe005;</i>添加父版块</a></li>
						<?php
						if(basename($_SERVER['SCRIPT_NAME'])=='father_module_update.php'){
							echo '<li><a href="#"><i class="icon-font">&#xe002;</i>编辑父板块</a></li>';
						}
						?>
                        <li><a href="son_module.php"><i class="icon-font">&#xe006;</i>子版块列表</a></li>
                        <li><a href="son_module_add.php"><i class="icon-font">&#xe005;</i>添加子版块</a></li>
						<?php
						if(basename($_SERVER['SCRIPT_NAME'])=='son_module_update.php'){
							echo '<li><a href="#"><i class="icon-font">&#xe002;</i>编辑子板块</a></li>';
						}
						?>
                        <li><a href="../index.php"><i class="icon-font">&#xe012;</i>帖子管理</a></li>
                    </ul>
                </li>
                <li>
                    <a href="#"><i class="icon-font">&#xe003;</i>用户管理</a>
                    <ul class="sub-menu">
                        <li><a href="member_list.php"><i class="icon-font">&#xe041;</i>用户列表</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
//footer.inc.php
</body>
</html>

效果

在这里插入图片描述

二、后台-父版块

父版块列表页

在这里插入图片描述

要实现上述效果。

思路

首先,引入文件config.inc.php、mysql.inc.php、tool.inc.php、header.inc.php、sidebar.inc.php。

其次,连接数据库、管理员是否登录验证、写出页面标题(在页面顶部文件输出)、执行sql增删改查对father_module数据表信息进行相关操作,在修改、添加版块,引入文件进行输入内容的相关验证(check_father_module.inc.php)。

最后,在以关联数组的方式获取一条记录的数据。在定界符区域内输出id、排序和父版块的名字,以及删除和修改超链接。点击删除,跳转到father_module_delete.php,通过获取的id删除指定版块。

点击修改,跳转到father_module_update.php通过sql语句的增删改查,进行修改。

父版块代码如下:

1.father_module.php

<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';
$template['title']='父板块列表页';
$query="select*from father_module";
$result=execute($link,$query);
?>
<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
<div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="index.php">后台首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">父版块列表</span></div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="father_module_add.php"><i class="icon-font"></i>新增板块</a>
                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th>
                            <th>排序</th>
							<th>ID</th>
                            <th>版块名称</th>
                            <th>操作</th>
                        </tr>
						<?php
						while($data=mysqli_fetch_assoc($result)){
							$url=urlencode("father_module_delete.php?id={$data['Id']}");
							$return_url=urlencode($_SERVER['REQUEST_URI']);
							$message="你真的要删除父版块 {$data['module_name']} 吗?";
							$delete_url="confirm.php?url={$url}&return_url={$return_url}&message={$message}";
$html=<<<A
							<tr>
								<td class="tc"><input name="id[]" value="59" type="checkbox"></td>
								<td>
									<input class="common-input sort-input" name="ord[]" value="{$data['sort']}" type="text">
								</td>
								<td>{$data['Id']}</td>
								<td>{$data['module_name']}</td>
								<td>
									<a class="link-update" href="father_module_update.php?Id={$data['Id']}">[修改]</a>
									<a class="link-del" href="$delete_url">[删除]</a>
								</td>
							</tr>
A;
							echo $html;
						}
						?>
                    </table>
                    <!--<div class="list-page"> 21/1</div>-->
                </div>
            </form>
        </div>
    </div>
    <!--/main-->
</div>
<?php
include_once 'inc/footer.inc.php';//footer
?>

2.father_module_delete.php

<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
	echo"<script type='text/javascript'>alert('id参数错误!');location='father_module.php';</script>";
	exit();
}
$link=connect();
include_once 'inc/is_manage_login.inc.php';
$query="delete from father_module where id={$_GET['id']}";
execute($link,$query);
if(mysqli_affected_rows($link)==1){
	skip('father_module.php','onCorrect.gif','恭喜你删除成功!');
}else{
	skip('father_module.php','onError.gif','对不起删除失败,请重试!');
}
?>

3.father_module_update.php

<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';
if(!isset($_GET['Id'])||!is_numeric($_GET['Id'])){
	skip('father_module.php','onError.gif','id参数错误!');
}
$query="select*from father_module where Id={$_GET['Id']}";
$result=execute($link,$query);
if(!mysqli_num_rows($result)){
	skip('father_module.php','onShow.gif','这个版块信息不存在!');
}
if(isset($_POST['submit'])){
	//验证用户填写的信息
	$check_flag='update';
	include 'inc/check_father_module.inc.php';
	$query="update father_module set module_name='{$_POST['module_name']}',sort={$_POST['sort']} where Id={$_GET['Id']}";
	execute($link,$query);
	if(mysqli_affected_rows($link)==1){
		skip('father_module.php','onCorrect.gif','修改成功!');
	}else{
		skip('father_module.php','onError.gif','修改失败,请重试!');
	}
}
$data=mysqli_fetch_assoc($result);
$template['title']='父板块修改页';
?>
<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
  <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="father_module.php">父版块列表</a><span class="crumb-step">&gt;</span><span class="crumb-name">修改父版块-<?php echo $data['module_name']?></span></div>
        </div>
		<form method="post">
		<div class="result-content">
                    <table class="result-tab" width="70%">
                        <tr>
                            <th class="tc" width="7%"><input class="allChoose" name="" type="checkbox"></th>
							<td>版块名称</td>
							<td><input type="text" name="module_name" class="common-text" value="<?php echo $data['module_name']?>"/></td>
							<td>版块名称不能为空,最多不超过40个字符</td>
						</tr>
						<tr>
							<th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
                            <td>排序</td>
							<td><input type="text" name="sort" class="common-text" value="<?php echo $data['sort']?>"/></td>
							<td>填入一个数字即可</td>
                        </tr>
					</table>
					<br />
					<input class="btn btn-primary btn6 mr10" type="submit" name="submit" value="修改" />
		</div>
		</form>
  </div>
</div>
<?php
include_once 'inc/footer.inc.php';//footer
?>

在对父版块的操作中,只有删除和修改是不够的。还应该有父版块添加页father_module_add.php。

4.father_module_add.php

<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';
if(isset($_POST['submit'])){
	$link=connect();
	//验证用户填写的信息
	$check_flag='add';
	include 'inc/check_father_module.inc.php';
	$query="insert into father_module(module_name,sort) values('{$_POST['module_name']}',{$_POST['sort']})";
	execute($link,$query);
	if(mysqli_affected_rows($link)==1){
		skip('father_module.php','onCorrect.gif','恭喜你,添加成功!');
	}else{
		skip('faher_module_add.php','onError.gif','对不起,添加失败,请重试!');
	}
}
$template['title']='父版块添加页';
?>
<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
  <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="father_module.php">父板块列表</a><span class="crumb-step">&gt;</span><span class="crumb-name">添加父版块</span></div>
        </div>
		<form method="post">
		<div class="result-content">
                    <table class="result-tab" width="70%">
                        <tr>
                            <th class="tc" width="7%"><input class="allChoose" name="" type="checkbox"></th>
							<td>版块名称</td>
							<td><input type="text" name="module_name" class="common-text" /></td>
							<td>版块名称不能为空,最多不超过40个字符</td>
						</tr>
						<tr>
							<th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
                            <td>排序</td>
							<td><input type="text" name="sort" class="common-text" /></td>
							<td>填入一个数字即可</td>
                        </tr>
					</table>
					<br />
					<input class="btn btn-primary btn6 mr10" type="submit" name="submit" value="添加" />
		</div>
		</form>
  </div>
</div>
<?php
include_once 'inc/footer.inc.php';//footer
?>

父版块添加页效果如下:

在这里插入图片描述

三、后台-子版块

子版块列表页
在这里插入图片描述

实现上述效果。除了sql语句操作的数据表(son_module)和输入内容验证文件(check_son_module.inc.php)不同外,其他和父版块类似,可以参考一下父版块的。

代码如下:

1.son_module.php

<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';
$template['title']='子板块列表页';
$query="select sm.id,sm.module_name,fm.module_name father_module_name,sm.member_id,sm.sort from son_module sm,father_module fm where sm.father_module_id=fm.id order by fm.id";
$result=execute($link,$query);
?>
<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
<div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="index.php">后台首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">子版块列表</span></div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="son_module_add.php"><i class="icon-font"></i>新增板块</a>
                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th>
                            <th>排序</th>
							<th>ID</th>
                            <th>版块名称</th>
							<th>所属父版块</th>
							<th>版主</th>
                            <th>操作</th>
                        </tr>
						<?php
						while($data=mysqli_fetch_assoc($result)){
							$url=urlencode("son_module_delete.php?id={$data['id']}");
							$return_url=urlencode($_SERVER['REQUEST_URI']);
							$message="你真的要删除父版块 {$data['module_name']} 吗?";
							$delete_url="confirm.php?url={$url}&return_url={$return_url}&message={$message}";
$html=<<<A
							<tr>
								<td class="tc"><input name="id[]" value="59" type="checkbox"></td>
								<td>
									<input class="common-input sort-input" name="ord[]" value="{$data['sort']}" type="text">
								</td>
								<td>{$data['id']}</td>
								<td>{$data['module_name']}</td>
								<td>{$data['father_module_name']}</td>
								<td>{$data['member_id']}</td>
								<td>
									<a class="link-update" href="#">[访问]</a>
									<a class="link-update" href="son_module_update.php?id={$data['id']}">[修改]</a>
									<a class="link-del" href="$delete_url">[删除]</a>
								</td>
							</tr>
A;
							echo $html;
						}
						?>
                    </table>
                </div>
            </form>
        </div>
    </div>
    <!--/main-->
</div>
<?php
include_once 'inc/footer.inc.php';//footer
?>

2.son_module_delete.php

<?php 
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
	skip('son_module.php','onError.gif','id参数错误!');
}
$link=connect();
include_once 'inc/is_manage_login.inc.php';
$query="delete from son_module where id={$_GET['id']}";
execute($link,$query);
if(mysqli_affected_rows($link)==1){
	skip('son_module.php','onCorrect.gif','恭喜你删除成功!');
}else{
	skip('son_module.php','onError.gif','对不起删除失败,请重试!');
}
?>

3.son_module_update.php

<?php 
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$template['title']='子版块修改页';
$link=connect();
include_once 'inc/is_manage_login.inc.php';
if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
	skip('son_module.php','onError.gif','id参数错误!');
}
$query="select * from son_module where id={$_GET['id']}";
$result=execute($link,$query);
if(!mysqli_num_rows($result)){
	skip('son_module.php','onError.gif','这条子版块信息不存在!');
}
$data=mysqli_fetch_assoc($result);
if(isset($_POST['submit'])){
	//验证
	$check_flag='update';
	include 'inc/check_son_module.inc.php';
	$query="update son_module set father_module_id={$_POST['father_module_id']},module_name='{$_POST['module_name']}',info='{$_POST['info']}',member_id={$_POST['member_id']},sort={$_POST['sort']} where id={$_GET['id']}";
	execute($link,$query);
	if(mysqli_affected_rows($link)==1){
		skip('son_module.php','onCorrect.gif','修改成功!');
	}else{
		skip('son_module.php','onError.gif','修改失败,请重试!');
	}
}
?>
<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
<div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="father_module.php">父板块列表</a><span class="crumb-step">&gt;</span><span class="crumb-name">添加子版块</span></div>
        </div>
		<form method="post">
		<div class="result-content">
                    <table class="result-tab" width="80%">
						<tr>
                            <th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
							<td>所属父版块</td>
							<td>
								<select name="father_module_id">
									<option value="0">===请选择一个父版块===</option>
									<?php
									$query="select*from father_module";
									$result_father=execute($link,$query);
									while ($data_father=mysqli_fetch_assoc($result_father)){
										if($data['father_module_id']==$data_father['Id']){
											echo "<option value='{$data_father['Id']}' selected='selected'>{$data_father['module_name']}</option>";
										}else{
											echo "<option value='{$data_father['Id']}'>{$data_father['module_name']}</option>";
										}
									}
									?>
								</select>
							</td>
							<td>*请选择一个父版块</td>
						</tr>
                        <tr>
                            <th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
							<td>版块名称</td>
							<td><input type="text" name="module_name" value="<?php echo $data['module_name']?>" class="common-text" /></td>
							<td>版块名称不能为空,最多不超过40个字符</td>
						</tr>
						<tr>
                            <th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
							<td>版块简介</td>
							<td>
								<textarea name="info" id="txtCon" rows="6" cols="50"><?php echo $data['info']?></textarea>
							</td>
							<td>版块名称不能为空,最多不超过300个字符</td>
						</tr>
						<tr>
                            <th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
							<td>版主</td>
							<td>
								<select name="member_id">
									<option value="0">===请选择一个会员作为版主===</option>
								</select>
							</td>
							<td>可以选择一个会员作为版主</td>
						</tr>
						<tr>
							<th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
                            <td>排序</td>
							<td><input type="text" name="sort" class="common-text" value="<?php echo $data['sort']?>"/></td>
							<td>填入一个数字即可</td>
                        </tr>
					</table>
					<br />
					<input class="btn btn-primary btn6 mr10" type="submit" name="submit" value="修改" />
		</div>
		</form>
  </div>
</div>
<?php include 'inc/footer.inc.php'?>

**同样,在子版块中,只有子版块列表是不够的。所以,也要实现子版块的添加。**其中应该选择一个所属父版块,用<option>标签实现列出所有父版块的名字。

4.son_module_add.php

<?php 
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$template['title']='子版块添加页';
$link=connect();
include_once 'inc/is_manage_login.inc.php';
if(isset($_POST['submit'])){
	//验证用户填写的信息
	$check_flag='add';
	include 'inc/check_son_module.inc.php';
	$query="insert into son_module(father_module_id,module_name,info,member_id,sort) values({$_POST['father_module_id']},'{$_POST['module_name']}','{$_POST['info']}',{$_POST['member_id']},{$_POST['sort']})";
	execute($link,$query);
	if(mysqli_affected_rows($link)==1){
		skip('son_module.php','onCorrect.gif','恭喜你,添加成功!');
	}else{
		skip('son_module_add.php','onError.gif','对不起,添加失败,请重试!');
	}
}
?>
<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
<div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="father_module.php">父板块列表</a><span class="crumb-step">&gt;</span><span class="crumb-name">添加子版块</span></div>
        </div>
		<form method="post">
		<div class="result-content">
                    <table class="result-tab" width="80%">
						<tr>
                            <th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
							<td>所属父版块</td>
							<td>
								<select name="father_module_id">
									<option value="0">===请选择一个父版块===</option>
									<?php
									$query="select*from father_module";
									$result_father=execute($link,$query);
									while($data_father=mysqli_fetch_assoc($result_father)){
										echo "<option value='{$data_father['Id']}'>{$data_father['module_name']}</option>";
									}
									?>
								</select>
							</td>
							<td>*请选择一个父版块</td>
						</tr>
                        <tr>
                            <th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
							<td>版块名称</td>
							<td><input type="text" name="module_name" class="common-text" /></td>
							<td>版块名称不能为空,最多不超过40个字符</td>
						</tr>
						<tr>
                            <th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
							<td>版块简介</td>
							<td>
								<textarea name="info" id="txtCon" rows="6" cols="50"></textarea>
							</td>
							<td>版块名称不能为空,最多不超过300个字符</td>
						</tr>
						<tr>
                            <th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
							<td>版主</td>
							<td>
								<select name="member_id">
									<option value="0">===请选择一个会员作为版主===</option>
								</select>
							</td>
							<td>可以选择一个会员作为版主</td>
						</tr>
						<tr>
							<th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
                            <td>排序</td>
							<td><input type="text" name="sort" class="common-text" /></td>
							<td>填入一个数字即可</td>
                        </tr>
					</table>
					<br />
					<input class="btn btn-primary btn6 mr10" type="submit" name="submit" value="添加" />
		</div>
		</form>
  </div>
</div>
<?php include 'inc/footer.inc.php'?>
四、后台-管理员

管理员列表

在这里插入图片描述

除操作数据表外,大致和父版块类似。要注意的是,管理员有超级管理员和普通管理员,超级管理员可以添加删除管理员,普通管理员不具有管理管理员操作权限。

1.manage.php

<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';
$template['title']='管理员列表页';
?>
<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
<div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="index.php">后台首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">管理员列表</span></div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="manage_add.php"><i class="icon-font"></i>新增管理员</a>
                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th>
							<th>ID</th>
                            <th>名称</th>	 	 	
							<th>等级</th>
							<th>创建日期</th>
							<th>操作</th>
                        </tr>
						<?php
						$query="select*from manage";
						$result=execute($link,$query);
						while ($data=mysqli_fetch_assoc($result)){
							if($data['level']==0){
								$data['level']='超级管理员';
							}else{
								$data['level']='普通管理员';
							}
							
							$url=urlencode("manage_delete.php?id={$data['Id']}");
							$return_url=urlencode($_SERVER['REQUEST_URI']);
							$message="你真的要删除管理员 {$data['username']} 吗?";
							$delete_url="confirm.php?url={$url}&return_url={$return_url}&message={$message}";
							
$html=<<<A
							<tr>
								<td class="tc"><input name="id[]" value="59" type="checkbox"></td>
								<td>{$data['Id']}</td>
								<td>{$data['username']}</td>
								<td>{$data['level']}</td>
								<td>{$data['create_time']}</td>
								<td><a href="{$delete_url}">[删除]</a></td>
							</tr>
A;
							echo $html;
						}
					?>
                    </table>
                </div>
            </form>
        </div>
    </div>
    <!--/main-->
</div>
<?php include_once 'inc/footer.inc.php';//footer?>

2.manage_delete.php

<?php 
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
	skip('manage.php','onError.gif','id参数错误!');
}
$link=connect();
include_once 'inc/is_manage_login.inc.php';
$query="delete from manage where id={$_GET['id']}";
execute($link,$query);
if(mysqli_affected_rows($link)==1){
	skip('manage.php','onCorrect.gif','恭喜你删除成功!');
}else{
	skip('manage.php','onError.gif','对不起删除失败,请重试!');
}
?>

3.manage_add.php

<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';
if(isset($_POST['submit'])){
	$link=connect();
	include 'inc/check_manage.inc.php';
	$query="insert into manage(username,password,create_time,level) values('{$_POST['username']}',md5({$_POST['password']}),now(),{$_POST['level']})";
	execute($link,$query);
	if(mysqli_affected_rows($link)==1){
		skip('manage.php','onCorrect.gif','恭喜你,添加成功!');
	}else{
		skip('manage.php','onError.gif','对不起,添加失败,请重试!');
	}
}
$template['title']='管理员添加页';
?>
<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
<div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="manage.php">管理员列表</a><span class="crumb-step">&gt;</span><span class="crumb-name">添加管理员</span></div>
        </div>
		<form method="post">
		<div class="result-content">
                    <table class="result-tab" width="70%">
                        <tr>
                            <th class="tc" width="7%"><input class="allChoose" name="" type="checkbox"></th>
							<td>管理员名称</td>
							<td><input type="text" name="username" class="common-text" /></td>
							<td>版块名称不能为空,最多不超过32个字符</td>
						</tr>
						<tr>
							<th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
                            <td>密码</td>
							<td><input type="text" name="password" class="common-text" /></td>
							<td>不能少于6</td>
                        </tr>
						<tr>
							<th class="tc" width="7%"><input class="allChoose" type="checkbox"></th>
                            <td>等级</td>
							<td>
								<select name="level">
									<option value="1">普通管理员</option>
									<option value="0">超级管理员</option>
								</select>
							</td>
							<td>请选择管理员等级,默认为普通管理员(不具备后台管理员管理权限)</td>
                        </tr>
					</table>
					<br />
					<input class="btn btn-primary btn6 mr10" type="submit" name="submit" value="添加" />
		</div>
		</form>
  </div>
</div>
<?php include_once 'inc/footer.inc.php';//footer?>

在这里插入图片描述

4.管理员登录login.php

<?php
header('Content-type:text/html;charset=utf-8');
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
if(is_manage_login($link)){
	skip('index.php','onCorrect.gif','您已经登录,请不要重复登录!');
}
if(isset($_POST['submit'])){
	include_once 'inc/check_login.inc.php';
	$_POST=escape($link,$_POST);
	$query="select * from manage where username='{$_POST['username']}' and password=md5('{$_POST['password']}')";
	$result=execute($link, $query);
	if(mysqli_num_rows($result)==1){
		$data=mysqli_fetch_assoc($result);
		$_SESSION['manage']['username']=$data['username'];
		$_SESSION['manage']['password']=sha1($data['password']);
		$_SESSION['manage']['id']=$data['Id'];
		$_SESSION['manage']['level']=$data['level'];
		skip('index.php','onCorrect.gif','登录成功!');
	}else{
		skip('login.php','onError.gif','用户名或者密码错误,请重试!');
	}
}
?>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理登录</title>
    <link href="css/admin_login.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="admin_login_wrap">
    <h1>后台管理登录</h1>
    <div class="adming_login_border">
        <div class="admin_input">
            <form method="post">
                <ul class="admin_items">
                    <li>
                        <label for="username">用户名:</label>
                        <input type="text" name="username" id="username" size="40" class="admin_input_style" />
                    </li>
                    <li>
                        <label for="password">密 码:</label>
                        <input type="password" name="password" id="password" size="40" class="admin_input_style" />
                    </li>
					<li>
						<label for="vcode">验证码:</label>
						<input name="vcode" type="text" size="40" class="admin_input_style" />
						<a href="login.php"><img class="vcode" src="../show_code.php" /></a>
					</li>
                    <li>
                        <input type="submit" name="submit" tabindex="3" value="提交" class="btn btn-primary" />
                    </li>
                </ul>
            </form>
        </div>
    </div>
    <p class="admin_copyright"><a tabindex="5" href="index.php" target="_blank">返回首页</a> &copy; 2019 Powered by <a href="http://qwzf.github.io" target="_blank">Q子枫</a></p>
</div>
</body>
</html>

在这里插入图片描述

5.管理员注销logout.php

<?php 
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
if(!is_manage_login($link)){
	header('Location:login.php');
}
else{
	session_unset();//Free all session variables
	session_destroy();//销毁一个会话中的全部数据
	setcookie(session_name(),'',time()-3600,'/');//销毁保存在客户端的卡号(session id)
	header('Location:login.php');
}
?>
五、后台-系统

1.系统信息index.php

在这里插入图片描述

要实现上述系统信息的显示,一些sql查询计数语句足矣!!

<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';

$query="select * from manage where id={$_SESSION['manage']['id']}";
$result_manage=execute($link, $query);
$data_manage=mysqli_fetch_assoc($result_manage);

$query="select count(*) from father_module";
$count_father_module=num($link,$query);

$query="select count(*) from son_module";
$count_son_module=num($link,$query);

$query="select count(*) from content";
$count_content=num($link,$query);

$query="select count(*) from reply";
$count_reply=num($link,$query);

$query="select count(*) from member";
$count_member=num($link,$query);

$query="select count(*) from manage";
$count_manage=num($link,$query);

if($data_manage['level']=='0'){
	$data_manage['level']='超级管理员';
}else{
	$data_manage['level']='普通管理员';
}
$template['title']='系统信息';
?>

<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
    <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font">&#xe06b;</i><span>欢迎管理员</span></div>
        </div>
        <div class="result-wrap">
            <div class="result-title">
                <h1>系统基本信息</h1>
            </div>
            <div class="result-content">
                <ul class="sys-info-list">
					<li>
						<label class="res-lab">您好: </label><span class="res-info"><?php echo $data_manage['username']?></span>
					</li>
					<li>
						<label class="res-lab">所属角色:</label><<span class="res-info"><?php echo $data_manage['level']?> </span>
					</li>
					<li>
						<label class="res-lab">创建时间:</label><span class="res-info"><?php echo $data_manage['create_time']?></span>
					</li>
                </ul>
			</div>
			<br />
			<div class="result-content">
				<ul>
					<li> 
						<span class="res-info">
							父版块(<?php echo $count_father_module?>)
							子版块(<?php echo $count_son_module?>)
							帖子(<?php echo $count_content?>)
							回复(<?php echo $count_reply?>)
							会员(<?php echo $count_member?>)
							管理员(<?php echo $count_manage?>)
						</span>
					</li>
				</ul>
			</div>
			<br />
			<div class="result-content">
				<ul>
					<li>
						<label class="res-lab">服务器操作系统:</label><span class="res-info"><?php echo PHP_OS?></span>
					</li>
					<li>
						<label class="res-lab">服务器软件:</label><span class="res-info"><?php echo $_SERVER['SERVER_SOFTWARE']?></span>
					</li>
					<li>
						<label class="res-lab">MySQL 版本:</label><span class="res-info"><?php echo  mysqli_get_server_info($link)?></span>
					</li>
					<li>
						<label class="res-lab">最大上传文件:</label><span class="res-info"><?php echo ini_get('upload_max_filesize')?></span>
					</li>
					<li>
						<label class="res-lab">内存限制:</label><span class="res-info"><?php echo ini_get('memory_limit')?></span>
					</li>
					<li>
						<span class="res-info"><a target="_blank" href="phpinfo.php">PHP 配置信息</a></span>
					</li>
				</ul>
			</div>
			<br />
			<div class="result-content">
				<ul>
					<li>
						<label class="res-lab">程序安装位置(绝对路径)</label><span class="res-info"><?php echo SA_PATH?></span>
					</li>
					<li>
						<label class="res-lab">程序在web根目录下的位置(首页的url地址)</label><span class="res-info"><?php echo SUB_URL?></span>
					</li>
					<li>
						<label class="res-lab">程序版本:</label><span class="res-info">Qwzf V1.0 <a target="_blank" href="#">[查看最新版本]</a></span>
					</li>
					<li>
						<label class="res-lab">程序作者:</label><span class="res-info">Qwzf </span>
					</li>
				</ul>
            </div>
			<br />
        </div>
    </div>
    <!--/main-->
</div>
<?php include_once 'inc/footer.inc.php';//footer?>

查看PHP配置信息时跳转到另一个页面,用PHP自带查询配置信息语句。

phpinfo.php

<?php 
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';//验证管理员是否登录
phpinfo();
?>

2.站点设置system.php

在这里插入图片描述

这是一个表单提交,提交网站标题、关键字、描述到数据库。且把网站标题从数据库查询,在页面标题处输出,即在顶部文件header.inc.php输出该页查询的网站标题。

<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';
$query="select * from info where Id=1";
$result_info=execute($link, $query);
$data_info=mysqli_fetch_assoc($result_info);
if(isset($_POST['submit'])){
	$_POST=escape($link,$_POST);
	$query="update info set title='{$_POST['title']}',keywords='{$_POST['keywords']}',description='{$_POST['description']}' where Id=1";
	execute($link, $query);
	if(mysqli_affected_rows($link)==1){
		skip('system.php','onCorrect.gif','修改成功!');
	}else{
		skip('system.php','onError.gif','修改失败,请重试!');
	}
}
$template['title']='站点设置页';
?>

<?php
include_once 'inc/header.inc.php';//top
include_once 'inc/sidebar.inc.php';//sidebar
?>
    <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="index.php">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">站点设置</span></div>
        </div>
        <div class="result-wrap">
            <form method="post">
                <div class="config-items">
                    <div class="config-title">
                        <h1><i class="icon-font">&#xe00a;</i>网站信息设置</h1>
                    </div>
                    <div class="result-content">
                        <table width="100%" class="insert-tab">
                                <tr>
                                    <th><i class="require-red">*</i>网站标题:</th>
                                    <td><input type="text" id="" value="<?php echo $data_info['title']?>" size="85" name="title" class="common-text"></td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>关键字:</th>
                                    <td><input type="text" id="" value="<?php echo $data_info['keywords']?>" size="85" name="keywords" class="common-text"></td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>描述:</th>
                                    <td><input type="text" id="" value="<?php echo $data_info['description']?>" size="85" name="description" class="common-text"></td>
                                </tr>
                                <tr>
                                    <th></th>
                                    <td>
                                        <input type="submit" value="提交" name="submit" class="btn btn-primary btn6 mr10">
                                        <input type="button" value="返回" onclick="history.go(-1)" class="btn btn6">
                                    </td>
                                </tr>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!--/main-->
</div>
<?php
include_once 'inc/footer.inc.php';//footer
?>

后台的基本功能已经实现了大部分,剩余的与前台有点关联,暂且先不做总结。。

感悟:

总结之后,对论坛后台开发,又有了新的认识。且熟悉了基本开发思路和流程。。后续我将会把论坛前台开发再总结一下。希望再次有所收获。。。小白进阶ing。。。。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值