$_GET变量
用于收集来自method=“get”的表单中的值
例如
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
名字: <input type="text" name="name">
年龄: <input type="text" name="age">
<input type="submit" value="Submit">
</form>
<?php echo $_GET['name']; ?><br>
<?php echo $_GET['age']; ?><br>
</body>
</html>
运行如下:
get到的输入会在URL中显示
在bugkuweb练习中的第三个
题中提示当what变量=flag时显示flag
在URL栏中加入?what=flag即可成功显示
$_POST变量
相对于$_GET而言,其作用也是获取表单信息,但是发送的信息对任何人不可见,不显示在URL栏中,因此通常用此方法来发送秘密性高的信息
具体代码如上大致相同:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
名字: <input type="text" name="name">
年龄: <input type="text" name="age">
<input type="submit" value="Submit">
</form>
<?php echo $_POST['name']; ?><br>
<?php echo $_POST['age']; ?><br>
</body>
</html>
运行如下,没有在URL栏中显示变量的信息
在bugkuweb练习中的第四个
这个题不能在URL中加入变量的值,应该用浏览器中的HackBar(因HackBar收费,暂时用Max HackBar),在上面一栏中输入题目的ip,勾选POST按钮,在下方栏中输入what=flag并点击Execution即可显示flag
include和require语句
include相当于调用执行其他文件的代码,执行时即使出错也不会停止,require和include作用相同,但出错时会停止运行
这里有一个index.php文件和123.php文件,其中前者无错误,后者出错
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<?php include 'index.php'; ?>
include执行
<?php require '123.php'; ?>
require执行
</body>
</html>
运行结果如下:
文件上传
此内容在菜鸟教程中学习得来
上传文件
在a.html中写入
<form action="test.php" method="post" enctype="multipart/form-data">
<label for="file">文件名:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="提交">
</form>
enctype决定上传文件的种类
创建上传脚本
在test.php中写入
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Document</title>
</head>
<body>
<?php
if($_FILES['file']['error']>0)
{
echo "错误:".$_FILES['file']['error']."<br>";
}
else
{
echo "上传文件名称:".$_FILES['file']['name']."<br>";
echo "上传文件的类型:".$_FILES['file']['type']."<br>";
echo "上传文件的大小:".$_FILES['file']['size']."<br>";
echo "文件临时存储的位置:".$_FILES['file']['tmp_name']."<br>";
if(file_exists("upload/".$_FILES['file'][name]."<br>"))
{
echo $_FILES['file']['name']."文件已经存在";
}
}
?>
</body>
</html>
最终结果运行如下:
Cookie
cookie 是一种服务器留在用户计算机上的小文件。每当同一台计算机通过浏览器请求页面时,这台计算机将会发送 cookie。通过 PHP能够创建并取回 cookie 的值。
在攻防世界中web新手区第四题
点击链接显示:
**1.**在url栏中输入cookie.php查看cookie
接下来显示:
查看响应头即可
**2.**可使用burp爆破来获取cookie
打开火狐浏览器,打开burp suite,并点击到‘on’状态
访问cookie.php