其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

http请求类型 POST请求

GG网络技术分享 2025-03-18 16:17 0


http请求类型 POST请求

请求参数放在header请求头中发送, url地址看不到请求参数,适合敏感信息

通常是通过表单提交并, 用来更新服务器上的信息

适合发送大量的数据到服务器端, 长度受到配置文件限制,但比GET要大得多

服务器端脚本使用预定义变量数组 $_POST 进行接收

<!DOCTYPE html>

<html lang=\"en\">

<head>

<meta charset=\"UTF-8\">

<title>POST</title>

</head>

<body>

<form action=\"\" method=\"post\">

<input type=\"email\" name=\"email\" value=\"\" placeholder=\"请输入邮箱\">

<input type=\"password\" name=\"password\" value=\"\" placeholder=\"请输入密码\">

<button>登录</button>

</form>

</body>

</html>

<?php

// form表单,获取的下标是 name 的值,下标名字是 form 表单 input 的 name

// 判断是否存在 $_POST[\'email\'] ,存在则输出

if( isset($_POST[\'email\']) ){

echo \'邮箱:\' . $_POST[\'email\'];

}

echo \'<br>\';

// 判断是否存在 $_POST[\'password\'] ,存在则输出

if( isset($_POST[\'password\']) ){

echo \'密码:\' . $_POST[\'password\'];

}

?>

输出结果

邮箱:921349888@qq.com

密码:123456

【PS】

POST请求, 参数不是通过URL传递, 而是通过请求头

获取通过url发送的变量参数, php通过超全局变量$_POST获取

$_POST是一个数组,键名就是POST参数名

键名=>变量名, 值=>变量值

本文章最后由 admin 于 2024-02-27 18:04 编辑

标签: 表单 参数

提交需求或反馈

Demand feedback