灵锡网-http请求类型 POST请求

灵锡网-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'];
    }
?>

输出结果

邮箱:344225443@qq.com

密码:123456

【PS】

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

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

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

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

感谢您的来访,获取更多精彩文章请收藏本站。

THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容