📅  最后修改于: 2023-12-03 15:22:35.552000             🧑  作者: Mango
这是一款使用 PHP 编写的,在登录系统的基础上增加了管理功能的 web 应用程序。
.
├── index.php // 首页,包含登录和注册功能
├── admin.php // 管理后台,可供管理员添加、修改和删除用户信息
├── logout.php // 退出登录页面
├── config.php // 数据库连接配置文件
├── functions.php // 封装的函数库文件
├── css/
│ ├── bootstrap.min.css
│ └── style.css
├── js/
│ └── bootstrap.min.js
├── img/
│ ├── avatar.png
│ └── favicon.ico
├── vendor/
│ ├── composer/
│ ├── autoload.php
│ ├── ...
│ └── ...
└── README.md
test
的数据库,执行以下 SQL 语句生成 users
表:CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` varchar(32) NOT NULL UNIQUE,
`password` varchar(64) NOT NULL,
`email` varchar(64) NOT NULL UNIQUE,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
config.php
文件,修改 MySQL 连接信息;index.php
即可。<?php
session_start();
require_once 'config.php';
require_once 'functions.php';
// 如果已登录则跳转到首页
if (is_logged_in()) {
redirect('index.php');
}
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 判断表单类型,执行不同的逻辑
switch ($_POST['type']) {
case 'register':
// 注册逻辑
register();
break;
case 'login':
// 登录逻辑
login();
break;
default:
// 默认逻辑
break;
}
}
// 渲染模板
render('index', [
'title' => '登录或注册',
]);
这款具有管理功能的 PHP 登录系统,不仅支持用户注册和登录,还能在管理员用户登录后提供管理功能。使用 PHP 和 MySQL 实现了用户信息的存储和读取。使用 Bootstrap 框架实现了用户友好的界面,非常适合初学者学习和实践。