Table of Contents
回复内容:
Home Backend Development PHP Tutorial form - php post提交数据 $_POST为空 file_get_content(php://input)可以获取到 这是为什么呢?

form - php post提交数据 $_POST为空 file_get_content(php://input)可以获取到 这是为什么呢?

Jun 06, 2016 pm 08:16 PM
form php post

php post提交数据 $_POST为空 file_get_content(php://input)可以获取到 这是为什么呢?
环境是用MAMP安装的
form提交的代码如下:

<code><div class="login_cont">
<form action="doLogin.php" method="post">
        <ul class="login">
            <li class="l_tit">管理员帐号</li>
            <li class="mb_10"><input type="text" name="username" placeholder="请输入管理员帐号" class="login_input user_icon"></li>
            <li class="l_tit">密码</li>
            <li class="mb_10"><input type="password" name="password" class="login_input password_icon"></li>
            <li class="l_tit">验证码</li>
            <li class="mb_10"><input type="text" name="verify" class="login_input password_icon"></li>
            <img src="/static/imghw/default1.png" data-src="getVerify.php" class="lazy" alt="">
            <li class="autoLogin">
<input type="checkbox" id="a1" class="checked" name="autoFlag" value="1"><label for="a1">自动登陆(一周内自动登陆)</label>
</li>
            <li><input type="submit" value="" class="login_btn"></li>
        </ul>
    </form>
</div>
</code>
Copy after login
Copy after login

doLogin.php的代码如下

<code>include_once '../include.php';

$username = $_POST['username'];
$password = md5($_POST['password']);
$verify = $_POST['verify'];
$session_verify = $_SESSION['verify'];
var_dump($_POST);
var_dump($_SERVER);

</code>
Copy after login
Copy after login

用花瓶抓包的结果:
form - php post提交数据 $_POST为空 file_get_content(php://input)可以获取到 这是为什么呢?

回复内容:

php post提交数据 $_POST为空 file_get_content(php://input)可以获取到 这是为什么呢?
环境是用MAMP安装的
form提交的代码如下:

<code><div class="login_cont">
<form action="doLogin.php" method="post">
        <ul class="login">
            <li class="l_tit">管理员帐号</li>
            <li class="mb_10"><input type="text" name="username" placeholder="请输入管理员帐号" class="login_input user_icon"></li>
            <li class="l_tit">密码</li>
            <li class="mb_10"><input type="password" name="password" class="login_input password_icon"></li>
            <li class="l_tit">验证码</li>
            <li class="mb_10"><input type="text" name="verify" class="login_input password_icon"></li>
            <img src="/static/imghw/default1.png" data-src="getVerify.php" class="lazy" alt="">
            <li class="autoLogin">
<input type="checkbox" id="a1" class="checked" name="autoFlag" value="1"><label for="a1">自动登陆(一周内自动登陆)</label>
</li>
            <li><input type="submit" value="" class="login_btn"></li>
        </ul>
    </form>
</div>
</code>
Copy after login
Copy after login

doLogin.php的代码如下

<code>include_once '../include.php';

$username = $_POST['username'];
$password = md5($_POST['password']);
$verify = $_POST['verify'];
$session_verify = $_SESSION['verify'];
var_dump($_POST);
var_dump($_SERVER);

</code>
Copy after login
Copy after login

用花瓶抓包的结果:
form - php post提交数据 $_POST为空 file_get_content(php://input)可以获取到 这是为什么呢?

首先php://input是不受php.ini设置行为的影响,可以直接获取到post的原始数据的.

$_POST是有受限于头限制的.英文手册(中文手册没有这段,略坑)中有如下介绍:

An associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request.

也就是你的Content-Type 只有是application/x-www-form-urlencoded 或者multipart/form-data的时候,才会被预定义的变量$_POST收进去.

另外一种情况可以考虑用$HTTP_RAW_POST_DATA,这个跟php://input获取到的数据是一样的,但是这个变量有受到php.ini中的选项always_populate_raw_post_data的限制.

form action="doLogin.php" 这里action的地址写成全路径试试。

action="./doLogin.php"

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles