04-28-周二_20-56-09
This commit is contained in:
210
课堂代码/01-blog开发/v4/README.md
Normal file
210
课堂代码/01-blog开发/v4/README.md
Normal file
@@ -0,0 +1,210 @@
|
||||
# 博客开发复盘
|
||||
|
||||
## 1. 安全渗透快速学习方法
|
||||
|
||||
1. 安全渗透涉及的面非常的广,所以对于从业人员来说需要有对一个陌生知识点快速学习的过程。
|
||||
|
||||
2. 安全渗透涉及到开发、运维、网络、物理硬件、数据库等多个领域
|
||||
|
||||
a. 开发领域:PHP、Python、Java、JavaScript等语言
|
||||
|
||||
b. 运维领域:Linux、Windows、Docker、Kubernetes等技术
|
||||
|
||||
c. 网络领域:TCP/IP、HTTP、DNS、CDN等技术
|
||||
|
||||
d. 物理硬件领域:硬件设备、硬件协议、硬件攻击等技术
|
||||
|
||||
e. 数据库领域:MySQL、MongoDB、Redis等技术
|
||||
|
||||
3. 安全渗透对于各个领域我们需要掌握最关键的技术点,并且对全局有一个整体的把握
|
||||
|
||||
## 2. 复盘博客开发思路
|
||||
|
||||
1. 设计需要的页面功能
|
||||
|
||||
a. 前台
|
||||
|
||||
- 给游客访问,可以直接查看文章,以及评论
|
||||
- 前台需要从数据库中读取所有的文章列表等信息
|
||||
- 前台支持查看文章的详细内容
|
||||
|
||||
b. 后台
|
||||
|
||||
- 用户管理
|
||||
- 文章管理
|
||||
- 评论管理
|
||||
- 系统管理
|
||||
|
||||
2. 设计数据库表结构
|
||||
- 数据库名称
|
||||
- 数据表的结构,id,username,password, email
|
||||
|
||||
3. 设计前端页面
|
||||
- 了解前端html,css的原理,通过和浏览器约定好的语法,让内容可以按照要求呈现
|
||||
- form表单是安全渗透必须要重点关注的,因为form涉及到数据传递
|
||||
- 请求方式,post,get也是重点关注的,因为涉及到与后端交互的数据
|
||||
|
||||
4. 将前端页面的功能一一实现
|
||||
- 使用php对数据库进行增删改查
|
||||
- 先获取需要的信息,比如文章id,用户的id,正文的内容,标题等等
|
||||
- 写sql语句
|
||||
- 执行sql语句
|
||||
- 拿到执行结果
|
||||
- 对结果进行处理,比如是否添加成功,查询到的详细数据处理
|
||||
|
||||
## 前端用到的技术
|
||||
|
||||
- 常见的标签
|
||||
- `<h1>` 标题
|
||||
- `<a href="">` 超链接,href是属性,点击跳转到的地址
|
||||
- `<p>` 段落
|
||||
- `<img src="">` 图片,src是属性,图片的地址是从网站根目录开始的
|
||||
- `<table><tr><td>` table是创建表格,tr是行,td是单元格
|
||||
- `<form action="" method="GET">` form是表单,用于前端网页向后端提交数据的,action表示往后端具体的地址提交内容,method表示往后端提交的方法
|
||||
- `post` 将数据放在请求体中,其实就是在网址发送后,请求头之后,添加数据,也是都用`&` 拼接
|
||||
- `get` 将所有的数据都用`?`和`&` 拼接在网址后,比如:`http://www.baidu.com/?name=user01&age=20`
|
||||
- `<input type="text" name="username">` 输入框,type是类型,name是名称,用于后端获取数据
|
||||
|
||||
## 后端用到的技术
|
||||
|
||||
- php本身即使超文本预处理语言,可以理解为html的扩充,所以直接写在html中,在php服务器上,会被直接处理执行,执行结构会自动拼接到html上,所以在浏览器上是无法看到php代码的,只能看到最终的html内容
|
||||
|
||||
- php的常见用法
|
||||
|
||||
- 定义变量
|
||||
|
||||
```php
|
||||
$name = "user01";
|
||||
echo $name;
|
||||
```
|
||||
|
||||
- 流程控制语句
|
||||
|
||||
```php
|
||||
if ($name == "user01") {
|
||||
echo "hello user01";
|
||||
} else {
|
||||
echo "hello guest";
|
||||
}
|
||||
|
||||
while ($i < 10) {
|
||||
echo $i;
|
||||
$i++;
|
||||
}
|
||||
```
|
||||
|
||||
- 获取前端传递的数据
|
||||
- 此处获得数据,是前端form中action提交过来的,并且input必须要有name属性
|
||||
- 获取方式有get和post,get是直接拼接在网址后,post是放在请求体中
|
||||
|
||||
```php
|
||||
// get方式
|
||||
$name = $_GET["name"];
|
||||
|
||||
// post方式
|
||||
$name = $_POST["name"];
|
||||
|
||||
// 不区分
|
||||
$name = $_REQUEST["name"];
|
||||
```
|
||||
|
||||
- 连接mysql数据库
|
||||
|
||||
```php
|
||||
$host = "127.0.0.1";
|
||||
$username = "root";
|
||||
$password = "usbw";
|
||||
$database = "blog";
|
||||
$port = 3307;
|
||||
$conn = mysqli_connect($host, $username, $password, $database, $port);
|
||||
if (!$conn) {
|
||||
exit("连接失败: " . mysqli_connect_error());
|
||||
}
|
||||
|
||||
// 设置字符集,防止中文乱码
|
||||
mysqli_connect("set names utf8");
|
||||
```
|
||||
|
||||
- 常用sql语句
|
||||
|
||||
```sql
|
||||
# 我是注释
|
||||
-- 我也是注释
|
||||
|
||||
-- 创建数据库
|
||||
create database blog;
|
||||
|
||||
-- 查看数据库
|
||||
show databases;
|
||||
|
||||
-- 进入到数据库中
|
||||
use blog
|
||||
|
||||
-- 查看表
|
||||
show tables;
|
||||
|
||||
-- 查找表
|
||||
select * from users;
|
||||
select * from users where id > 2;
|
||||
select * from users where username='user01' and password='123123';
|
||||
select username,avatar from users;
|
||||
select * from test where name like "李%";
|
||||
|
||||
-- 创建表
|
||||
-- primary key表示唯一,且非空
|
||||
-- auto_increment表示自增,每次插入数据时,id会自动加1
|
||||
-- comment表示注释
|
||||
-- enum表示枚举类型,只能是男或者女
|
||||
-- set表示集合类型,只能是1班、2班、3班
|
||||
-- datetime表示日期时间,默认是当前时间,格式是yyyy-mm-dd hh:mm:ss
|
||||
create table test(
|
||||
id int primary key auto_increment,
|
||||
name varchar(20) not null comment '用户名',
|
||||
age int not null comment '年龄',
|
||||
gender enum('男','女') comment '性别' default '女',
|
||||
class set('1班','2班','3班') not null comment '班级',
|
||||
address varchar(100) not null comment '地址',
|
||||
create_time datetime comment '创建时间' default now()
|
||||
)default charset=utf8;
|
||||
|
||||
-- 插入数据
|
||||
insert into test value(1, '张三', 18, '男', '1班', '北京市海淀区', now());
|
||||
insert into test(name,class,address) value("李四","1班","上海市");
|
||||
insert into test(name,class,address) value("李四","4班","上海市");
|
||||
insert into test(name,age,class,address) value
|
||||
("王五",20,"1班","北京市"),
|
||||
("赵六",21,"2班","北京市"),
|
||||
("孙七",22,"3班","北京市");
|
||||
|
||||
-- 删除数据
|
||||
delete from test where id=3;
|
||||
|
||||
-- 清空数据
|
||||
truncate table test;
|
||||
|
||||
-- 查看表结构
|
||||
desc test;
|
||||
explain test;
|
||||
|
||||
-- 修改数据
|
||||
update test set age=19 where id=2;
|
||||
|
||||
-- 删表
|
||||
drop table test;
|
||||
```
|
||||
|
||||
- 增加数据
|
||||
|
||||
```php
|
||||
$username = $_POST["username"];
|
||||
$password = $_POST["password"];
|
||||
$email = $_POST["email"];
|
||||
$sql = "INSERT INTO users (username, password, email) VALUES ('$username', '$password', '$email')";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
if ($result) {
|
||||
echo "添加成功";
|
||||
} else {
|
||||
echo "添加失败: " . mysqli_error($conn);
|
||||
}
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user