第一步:在layui官网下载官方模板经典模块化前端UI
第二步:完成注册登录操作
新建一个php文件,复制网上已有的MySQL数据库类:完整的PHP MySQL数据库类
将下载的html文件重命名为php文件,在login.php里添加一段脚本,用ajax方法将账号密码提交至checkUser.php,checkUser.php负责查询数据库,判断该用户是否存在及密码是否正确,将返回true or flase。返回的记录将被ajax xmlhttp.resposText接收,判断如果是true则登录成功跳转到首页,否则提示用户重新输入。


如果账号密码匹配则将账号放入session,用于首页判断是否已登录。其中include_once引用了function.php:

同理注册由ajax xmlhttp.open()将注册信息提交至register.php,交由其完成insert操作



二、首页
在首页显示帖子及其信息(回复数量、点赞数量、发帖时间)
首先判断用户是否已经登录
<?php
session_start();
if($_SESSION['mail']==null){
?> -----未登录时导航栏内容---- <?php } ?>
<?php
session_start();
if($_SESSION['mail']!=null){
$myemail=$_SESSION['mail'];
$myname = myname($myemail);
?> -----登录时导航栏内容---- <?php }>
显示用户名


接下来显示帖子
在function.php中编写函数查找帖子相关信息



完成后的效果

三、我的主页搭建

查询当前用户的信息存放在session中,home.php中将用到,将一一替换用户名、性别、所在城市等基本信息,这里不多余展示

输出我发出的所有博客,完善其信息


完成后的效果

四、基本设置
1、我的资料
form表单上传输入的信息到resetinfo.php

resetinfo.php接受数据并调用setinfo()函数对数据库进行update操作

2、修改密码
form表单上传输入数据至resetpass.php

resetpass.php调用repass()函数对数据库进行update操作

3、我的消息

消息回复显示,根据自己的id 联合回复表(answer)和 发帖表(post)查询回复的消息

在message.php中引用并填充




删除操作:删除按钮绑定remove事件

四、实现点进博客链接后跳转到博客内容页面
首先赋给每个博客一个id,就用它在数据库里的id , 页面跳转的链接后面跟 ?Pid=...,目的是为了后面ajax将url里面的参数传入php,再点这个链接跳转时就能跳到帖子对应的页面


php中request获取用ajax传过来的url参数,并调用在function里写的content函数查询博客内容


与帖子相关信息同理填充 效果如下

网友评论