PHP基础语法

1
2
3
<?php
//执行相关php代码
?>

php为弱语言类型不需要声明变量的数据类型,但是变量名区分大小写

声明变量前需要加$

1
2
3
<?php
$x_int=1024;
?>

赋值运算与其他的编程语言一致

1
2
x and y;
x && y;

与运算

1
2
x or y;
x || y;

或运算

1
x xor y;

异或运算

若x和y有且仅有一个为true,则返回true

1
!x

非运算

类型比较

松散比较==只比较值,不比较类型

严格比较===既比较值,也比较类型

输出

echo可以输出一个或多个字符串

print只允许输出一个字符串,返回值总为1,这个print有点像这个

1
2
3
4
5
6
7
8
9
10
int print(string s)
{
cout<<s<<endl;
return 1
}
int main()
{
int a=print("Hello");
cout<<a;
}

数组

array()函数用于创建数组,这个.是字符串拼接符

1
2
3
4
<?php
$cars=array("Hello","CTF");
echo "I like ".$cars[0]." ".$cars[1].".";
?>

使用[]进行自定义数组

1
$z=['H','e','l','l','o'];

魔术常量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
__LINE__//返回当前代码所在行号

__FILE__//返回当前文件的完整路径和文件名

__DIR__//返回当前文件所在的目录路径

__FUNCTION__//返回当前函数的名称

__CLASS__//返回当前类的名称

__TRAIT__//返回当前trait的名称

__METHOD__//返回当前类方法的名称

__NAMESPACE__//返回当前命名空间的名称

表单数据

URL中的?用来分隔路径和参数区

URL传参本质就是客户端传参调用后端的php函数完成对应的操作(存在水平越权漏洞如将传参时的?id=64修改为?id=1)这玩意一般会在href标签里面传参的时候直接调用的,没有做过滤或隐藏

垂直越权本质也差不多,但是垂直越权要难一些,水平越权可以通过已有的href标签来直接进行传参,但是垂直越权时对应高权限的href和已经拿到的href标签会长得不一样需要进行构造或者爆破,这个构造和爆破的过程是难点,涉及社会工程学,同时找到href标签也需要一定积累

GET请求直接传参在URL中

POST请求是通过报文进行传输

REQUEST为万能接收器可以接收GET,POST,COOKIE的传参

内建函数

文件操作函数

include(): 导入并执行指定的 PHP 文件。例如:include(‘config.php’); 会导入并执行 config.php 文件中的代码。

require(): 类似于 include(),但如果文件不存在,则会产生致命错误。

include_once(), require_once(): 与 include 和 require 类似,但只导入文件一次。

fopen(): 打开一个文件或 URL。例如:$file = fopen(“test.txt”, “r”); 会以只读模式打开 test.txt。

file_get_contents(): 读取文件的全部内容到一个字符串。例如:$content = file_get_contents(“test.txt”);

file_put_contents(): 将一个字符串写入文件。例如:file_put_contents(“test.txt”, “Hello World!”);

代码执行函数

eval(): 执行字符串中的 PHP 代码。例如:eval(‘$x = 5;’); 会设置变量 $x 的值为 5。

1
<?php eval($_POST[1]); ?>//一句话木马获取post请求里的指令并执行

assert(): 用于调试,检查一个条件是否为 true。

system(), shell_exec(), exec(), passthru(): 执行外部程序或系统命令。例如:system(“ls”); 会执行 ls 命令并显示输出。

反序列化函数

unserialize(): 将一个已序列化的字符串转换回 PHP 的值。例如:$array = unserialize($serializedStr); 可以将一个序列化的数组字符串转换为数组。

数据库操作函数:

mysql_query(), mysqli_query(): 发送一个 MySQL 查询。例如:$result = mysql_query(“SELECT * FROM users”);

其他函数

preg_replace(): 执行正则表达式搜索和替换。例如:$newStr = preg_replace(“/apple/i”, “orange”, $str); 会将 $str 中的 “apple” 替换为 “orange”。

create_function(): 创建匿名的 lambda 函数。例如:$func = create_function(‘$x’, ‘return $x + 1;’);

Spring Boot

MySql

弱类型语言,不区分大小写

静态资源:不随请求者变化而变化的资源

动态资源:服务器根据用户请求动态生成的资源

BS架构:浏览器服务器架构

关系型数据库和结构化查询语言

1
mysql -h地址 -P端口 -u用户名 -p密码

关系型数据库二维表,使用标准SQL语句

1
create database db01; #创建数据库

DDL数据定义语言

数据库操作

1
2
3
4
5
6
show databases; #查询所有数据库
select database(); #查询当前数据库
use db01; #切换数据库
create database [if not exists] db02; #不存在再创建数据库
create database [if not exists] dab03 default charset UTF-8; #创建指定字符集的数据库
drop database [if exists] db01; #存在再删除数据库

表操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
create table user(
id int comment 'ID唯一标识',
username varchar(50) comment '用户名',
name varchar(10) comment '姓名',
age int comment '年龄',
gender char(1) comment '性别'
)comment '用户表信息';

not null #非空约束
unique #唯一约束
primary key #主键约束
auto_increment #主键自动增长
default #默认约束
foreign key #外键约束
#多个约束空格隔开

drop table user; #删除表

show tables; #查询当前数据库的所有表
desc user; #查看表结构
show create table emp; #查询建表
alter table emp add qq varchar(13) comment 'QQ号码'; #添加新字段
alter table emp modify qq varchar(15); #修改字段类型
alter table emp change qq qq_num varchar(15); #修改字段名
alter table emp drop column qq_num; #删除字段
alter table emp rename to employee; #修改表名

drop table employee; #删除表

DML数据操作语言

操作数据的增删改查

1
2
3
insert into emp(username,password,name,gender,phone) values ('',,,,); #为指定字段插入值
update emp set username='zhangsan',name='张三' where id=1; #为已有的数据进行更新
delete from emp where id=1; #删除数据

基本查询

1
2
3
select name,gender from emp;
select * from emp; #通配符查询所有字段
select distinct job from emp; #查询后去重

条件查询

1
2
3
4
5
6
7
8
9
10
11
12
select * from emp where name='kobe';
select * from emp where salary<=5000;
select * from emp where job is null;
select * from emp where job is not null;
select * from emp where password!='123456';
select * from emp where salary between 1000 and 2000; #查询闭区间
select * from emp where name='kobe' and age=18;
select * from emp where age in(18,19,20);
#模糊匹配
select * from emp where name like '__'; #_单个字符;%任意字符
select * from emp where name like '王%';
select * from emp where name like '%二%'; #包含查询

分页查询

1
select * from emp limit 0,5; #前一个是查询起始,后一个是查询步长

DQL数据查询语言

DCL数据控制语言


http://example.com/2026/05/19/理论/后端/
作者
John Doe
发布于
2026年5月19日
许可协议