Background landing page login.php
$adminuser, 'id' => $res['id']]
);
$login_at = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'] == '::1' ? '127.0.0.1' : $_SERVER['REMOTE_ADDR'];
$login_ip = ip2long($ip);
$sql = "UPDATE {$prefix}admin
SET login_at = '$login_at', login_ip = '$login_ip'
WHERE id = '{$res['id']}'";
execute($sql);
//4. Go to https://www.cnblogs.com/chenying0/p/index.php
header('location: https://www.cnblogs.com/chenyingying0/p/index.php');
} else {
Setinfo ('wrong user name or password ');
}
}
?>
Shopping Mall
Sign in
以管理员身份Sign in后台
user name
password
Sign in
Database structure shop.sql
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `test_admin`;
CREATE TABLE `test_admin` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`adminuser` varchar(50) NOT NULL DEFAULT '',
`adminpass` char(32) NOT NULL DEFAULT '',
`created_at` varchar(255) NOT NULL DEFAULT '',
`login_at` varchar(255) NOT NULL DEFAULT '' ,
`login_ip` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
BEGIN;
INSERT INTO `test_admin` VALUES (1, 'admin', '0192023a7bbd73250516f069df18b500', '2019-01-23 20:21:03', '2019-01-24 12:56:48', 2130706433);
COMMIT;
DROP TABLE IF EXISTS `test_cart`;
CREATE TABLE `test_cart` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00',
`quantity` int(10) unsigned NOT NULL DEFAULT '0',
`products` text,
`uid` int(10) unsigned NOT NULL DEFAULT '0',
`created_at` varchar(255) NOT NULL DEFAULT '' ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
BEGIN;
INSERT INTO `test_cart` VALUES (2, 21700.00, 3, '{\"3\":{\"quantity\":2,\"product\":{\"id\":\"3\",\"name\":\"Macbook Pro\",\"price\":\"8800.00\",\"code\":\"88888888\",\"description\":\"Macbook Pro\"}},\"4\":{\"quantity\":1,\"product\":{\"id\":\"4\",\"name\":\"\u534e\u4e3a\u624b\u673a\",\"price\":\"4100.00\",\"code\":\"929868123123123\",\"description\":\"\u5546\u54c1\u63cf\u8ff0\uff1a\r\n\r\n\u8fd9\u662f\u534e\u4e3a\u624b\u673a\"}}}', 5, '2019-01-24 10:53:24');
COMMIT;
DROP TABLE IF EXISTS `test_order`;
CREATE TABLE `test_order` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00',
`quantity` int(10) unsigned NOT NULL DEFAULT '0',
`products` text,
`uid` int(10) unsigned NOT NULL DEFAULT '0',
`created_at` varchar(255) NOT NULL DEFAULT '' ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
BEGIN;
INSERT INTO `test_order` VALUES (1, 17600.00, 2, '{\"3\":{\"quantity\":2,\"product\":{\"id\":\"3\",\"name\":\"Macbook Pro\",\"price\":\"8800.00\",\"code\":\"88888888\",\"description\":\"Macbook Pro\"}}}', 5, '2019-01-24 12:46:33');
COMMIT;
DROP TABLE IF EXISTS `test_product`;
CREATE TABLE `test_product` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL DEFAULT '',
`code` varchar(100) NOT NULL DEFAULT '',
`description` text,
`stock` int(10) unsigned NOT NULL DEFAULT '0',
`price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00',
`created_at` varchar(255) NOT NULL DEFAULT '' ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
BEGIN;
INSERT INTO `test_product` VALUES (3, 'Macbook Pro', '88888888', 'Macbook Pro', 99, 8800.00, '2019-01-24 00:19:28');
INSERT INTO `test_ Product ` values (4, 'Huawei Mobile', '929868123123', product description: \ R \ n \ R \ n this is Huawei Mobile ', 99, four thousand and one hundred , '2019-01-24 00:31:28');
COMMIT;
DROP TABLE IF EXISTS `test_user`;
CREATE TABLE `test_user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(100) NOT NULL DEFAULT '',
`password` char(32) NOT NULL DEFAULT '',
`name` varchar(100) NOT NULL DEFAULT '',
`age` tinyint(3) unsigned NOT NULL DEFAULT '0',
`email` varchar(100) NOT NULL DEFAULT '',
`phone` varchar(20) NOT NULL DEFAULT '',
`created_at` varchar(255) NOT NULL DEFAULT '' ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
BEGIN;
Insert into ` test_user ` values (3, 'Zhangsan', '4297f44b13955235245b2497399d7a93', 'Zhang San', 28, '965794175 @ QQ. Com', '13200000000', '2019-01-23 23 23:54:34');
INSERT INTO `test_user` VALUES (4, 'wangwu', '4297f44b13955235245b2497399d7a93', '', 0, '[email protected]', '', '2019-01-24 09:21:45');
INSERT INTO `test_user` VALUES (5, 'zhaoliu', '4297f44b13955235245b2497399d7a93', '', 0, '[email protected]', '', '2019-01-24 09:35:05');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;
Configuration database file config.php
'127.0.0.1',
'DB_PORT' => '3306',
'DB_USER' => 'root',
'DB_PASS' => '123456',
'DB_NAME' => 'test_shop',
'DB_PREFIX' => 'test_',
'DB_CHARSET' => 'utf8',
];
Operation database function db.func.php
0) {
$data = ($result);
}
return $data;
}
function query($sql)
{
$mysqli = connect();
$result = ($mysqli, $sql);
$data = [];
if ($result && ($result) > 0) {
while ($res = ($result)) {
$data[] = $res;
}
}
return $data;
}
function getDBPrefix()
{
$config = require (__FILE__) . '/config.php';
return $config['DB_PREFIX'];
}
function execute($sql)
{
$mysqli = connect();
($mysqli, $sql);
return ($mysqli) > 0;
}
Common function file tools.func.php
<?php /**
* Created by PhpStorm.
* Date: 2019/1/23
* Time: 20:31
*/
function setSession($key, $data, $prefix = '')
{
() || @();
if (!empty($prefix)) {
$_SESSION[$prefix][$key] = $data;
} else {
$_SESSION[$key] = $data;
}
}
function getSession($key, $prefix = '')
{
() || @();
if (!empty($prefix)) {
return isset($_SESSION[$prefix][$key]) ? $_SESSION[$prefix][$key] : [];
} else {
return isset($_SESSION[$key]) ? $_SESSION[$key] : [];
}
}
function deleteSession($key, $prefix = '')
{
() || @();
if (!empty($prefix)) {
$_SESSION[$prefix][$key] = null;
} else {
$_SESSION[$key] = null;
}
}
function setInfo($info)
{
setSession('info', $info, 'system');
}
function getInfo()
{
$info = getSession('info', 'system');
deleteSession('info', 'system');
return $info;
}
function hasInfo()
{
return !empty(getSession('info', 'system'));
}
Judge whether there is login permission auth.php
<?php /**
* Created by PhpStorm.
* Date: 2019/1/23
* Time: 22:07
*/
if (empty(getSession('adminuser', 'admin'))) {
('location: login.php');
exit;
}
Log in successfully and enter the background Homepage https://www.cnblogs.com/chenyingying0/p/index.php
All administrators
控制台All administrators列表
ID
user name
Creation time
Last login time
Last login IP
header.php
Shopping Mall
Shopping Mall
dashboard
Console
person
user management
library_books
Commodity management
shopping_cart
Shopping cart management
list
Order management
Console
person
administrators
edit
sign out
footer.php
Change the password of administrator account https://www.cnblogs.com/chenying0/p/admin_edit.php
Change Password
Modify the current administrator password
user name
Old password
New password
Confirm password
modify
The administrator logs out https://www.cnblogs.com/chenying0/p/logout.php in the background
<?php /**
* Created by PhpStorm.
* Date: 2019/1/23
* Time: 22:06
*/
// 1. 删除当前登录用户的session
require '../tools.func.php';
deleteSession('admin');
('location: login.php');
The user list shows https://www.cnblogs.com/chenyingying0/p/users.php
All users
User list
Add user
ID
user name
full name
Age
mailbox
contact number
Registration time
operation
edit
|
delete
Add user https://www.cnblogs.com/chenying0/p/user’add.php
Add user
Add a user
user name
password
确认password
full name
Age
contact number
mail box
Add user
Modify user information user_ edit.php
Modify user
Modify a user
user name
full name
Age
contact number
mail box
Update information
Delete user user? Del.php
<?php /**
* Created by PhpStorm.
* Date: 2019/1/24
* Time: 10:49
*/
require '../db.func.php';
require '../tools.func.php';
require 'auth.php';
// 1. 接收id
$id = ($_GET['id']);
// 2. 从数据库当中删除对应的数据
$prefix = getDBPrefix();
$sql = "DELETE FROM {$prefix}user WHERE id = '$id'";
if (execute($sql)) {
setInfo('删除成功');
} else {
setInfo('删除失败');
}
// 3. 跳回到列表页
('location: https://www.cnblogs.com/chenyingying0/p/users.php');
Product list https://www.cnblogs.com/chenying0/p/products.php
All products
All products列表
Add item
ID
Item No
Commodity name
Product description
Merchandise inventory
item pricing
Time of goods on the market
edit
edit
|
delete
Add product https://www.cnblogs.com/chenying0/p/product_add.php
Add item
Add a product
Commodity name
item pricing
Merchandise inventory
Item No
Product description
Add item
Shopping cart list page https://www.cnblogs.com/chenying0/p/cards.php
All shopping carts
All shopping carts列表
ID
Shopping cart users
Total merchandise
Total price of shopping cart
Add time
edit
delete
Order list https://www.cnblogs.com/chenying0/p/orders.php
All orders
All orders列表
ID
Order user
Order price
Order item quantity
Order time