【问题标题】:$_POST always empty, $_GET works, php://input works$_POST 始终为空,$_GET 有效,php://input 有效
【发布时间】:2016-01-16 23:08:49
【问题描述】:

我正在使用 XAMPP 开发一个网站,但出于某种深不可测的原因,无论我尝试什么,$_POST 总是为空。

<form id="reg-form" method="post" action="check.php" enctype="application/x-www-form-urlencoded">
    <label for="user" form="reg-form">Username: </label>
    <input type="text" id="user" name="user" title="Username">
    <br />
    <label for="pass" form="reg-form">Password: </label>
    <input type="password" id="pass" name="pass" title="Password">
    <br />
    <input type="submit" id="submit" title="Submit" value="Submit" form="reg-form">
</form>

这里是 check.php:

<?php
if(empty($_SERVER['CONTENT_TYPE'])){

    $type = "application/x-www-form-urlencoded";

    $_SERVER['CONTENT_TYPE'] = $type;

}
var_dump($_POST);
print_r($_POST);
print_r($_GET);
$data = file_get_contents('php://input');
echo($data);

?>

然后输出: 数组(0) { } 数组( ) 数组( ) user=test&pass=test

如果我将方法更改为 GET,则 get 数组会毫无问题地填充。

我检查了 php.ini,post 已启用,我在 variable_order 中有 GCPS,post_max_size 为 8M,但我尝试更改它,但没有帮助。

我已经束手无策了,再多的谷歌搜索似乎也无济于事。我是否忽略了一些非常简单的事情?

【问题讨论】:

  • 尝试删除enctype并从提交按钮中删除form
  • 您应该检查您的 php.ini 是否将 enable_post_data_reading 设置为 false。如果设置为false,则永远不会填充$_POST...
  • @MousE0910 更多猜测。 1. 检查variables_order 是否设置正确,是否包含P。 2、post_max_size呢? 3. 尝试关闭 apache mod_security。如果没有任何帮助,我们将需要更多信息,例如您的 PHP 版本、系统等。
  • @MousE0910 您使用的是 windows 还是 *nix?你在运行 suhosin 吗? (不知道它是否与xampp一起提供)。如果是这样,请将其关闭:suhosin.simulation = Off in php.ini

标签: php post get


【解决方案1】:

更新我想通了。我使用的是 phpStorm,它没有正确配置为使用 XAMPP,而是使用它自己的服务器。一旦我正确配置它,突然之间,post 就按预期工作了。经验教训:在使用 IDE 之前,请务必正确阅读文档。

【讨论】:

    猜你喜欢
    • 2021-02-21
    • 2013-07-19
    • 1970-01-01
    • 2018-08-08
    • 2012-12-29
    • 2013-12-23
    • 2015-10-09
    • 2014-04-05
    • 1970-01-01
    相关资源
    最近更新 更多